ADO.NET

ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples

Examples

Retrieving Data Using a SQL Server Stored Procedure IN ASP.NET
Previous Home Next

Step 1. The Design Code is.

<%@PageLanguage="C#"AutoEventWireup="true"
Codevirtual="Default.aspx.cs"Inherits="_Default"%>
<%@Registerassembly="AjaxControlToolkit"
namespace="AjaxControlToolkit"tagprefix="cc1"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title>UntitledPage</title>
</head>
<body><formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"
BorderStyle="Solid"BorderWidth="2px"
Height="86px"
Width="258px">
<RowStyleBackColor="White"BorderColor="#333333"BorderStyle="Solid"
BorderWidth="2px"/>
<Columns><asp:BoundFieldDataField="nme"HeaderText="Name"/>
<asp:BoundFieldDataField="age"HeaderText="Age"/>
<asp:BoundFieldDataField="emp_id"HeaderText="EmployeID"/>
</Columns>
<SelectedRowStyleBorderStyle="Solid"/>
<HeaderStyleBackColor="#CCCCCC"BorderStyle="Inset"BorderWidth="2px"/>
<EditRowStyleBorderStyle="Solid"BorderWidth="2px"/>
</asp:GridView></div>
<br/><br/>
</form>
</body>
</html>

Stored Procedure:

CREATE PROCEDURE  SelectEmpDetails @id nchar(10)
AS
BEGIN
SELECT * FROM  emp_tbl  WHERE  emp_ID=@id
END

 

Step 2: Default.aspx.cs Code.

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection newConnection = new 
SqlConnection(@"Data Source=R4R-3EFD13BB468\SQLEXPRESS; 
initial catalog=newDatabase;integrated security=true;");
protected void Page_Load(object sender, EventArgs e)
{
newConnection.Open();
SqlCommand cmdd = new SqlCommand("SelectEmpDetails", newConnection);
cmdd.CommandType = CommandType.StoredProcedure;
cmdd.Parameters.Add("@id", SqlDbType.Int).Value = 1234;
SqlDataReader dr = cmdd.ExecuteReader();
if (dr.HasRows)
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
newConnection.Close();
}
}

OutPut:

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: