How to use Stored Procedure In ASP .Net.
please send samples with Examples.
Thanks&Regs
Manavalan
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 2, 2012, 9:01 PM EST
Here is an example how to display records using stored procedure.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Stored_procedure_to_display._Default" %>
using System;
using System.Collections;
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;
namespace Stored_procedure_to_display
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
com = new SqlCommand("display", con);
com.CommandType = CommandType.StoredProcedure;
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
GridView1.DataSource = ds;
GridView1.DataMember = "student";
GridView1.DataBind();
con.Close();
}
}
}
Stored procedure
ALTER PROCEDURE display
AS
select * from student
Thanks
If this post helps you mark it as answer
magesh manavalanRank #6,279 · 271 reputationPosted Mar 2, 2012, 11:49 PM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 3, 2012, 12:07 AM EST
If this post helps you mark it as answer
Thanks
SenthilkumarRank #387 · 6.5K reputationPosted Mar 6, 2012, 7:26 PM EST
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandType = CommandType.StoredProcedure; //Three Types: Text, StoredProcedure, TableDirect
sqlCommand.Text = "proc_AddTwoNumbers";
if you have parameter to the stored procedure then
sqlCommand.Parameters.Add("@ProcedureArqument1",ParamValue1);
sqlCommand.Parameters.Add("@ProcedureArqument2",ParamValue2);
The first arqument is the sql stored procedure paramter name, passing value and the third parameter is data type.