| Author: sheetal 15 Feb 2009 | Member Level: Bronze Points : 2 |
Sample Code for Stored Procedure in ASP.net =====Creating customers table==== CREATE TABLE [dbo].[customers]( [cid] [int] NOT NULL, [bal] [money] NULL )
=======Creating a stored procedure======= Create procedure prc_getBal(@cid int,@bal money output) As Begin Select @bal=bal from customers where cid=@cid End
=====Calling the Stored Procedure====== ------------------ ------------------ using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection("User ID=sa;Password=pass;Initial Catalog=test;Data Source=Personal"); SqlCommand cmd; protected void Page_Load(object sender, EventArgs e) { con.Open(); } protected void BtnSubmit_Click(object sender, EventArgs e) { int cid=Convert.ToInt16(TxtID.Text); cmd=new SqlCommand("prc_getBal",con);
cmd.Parameters.AddWithValue("@cid",cid); cmd.Parameters.AddWithValue("@bal",SqlDbType.Money).Direction=ParameterDirection.Output; cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); Response.Write(cmd.Parameters["@bal"].Value); con.Close(); } }
|
| Author: Sasikumar 18 Feb 2009 | Member Level: Gold Points : 2 |
Sample Code for Stored Procedure in ASP.net =====Creating customers table==== CREATE TABLE [dbo].[customers]( [cid] [int] NOT NULL, [bal] [money] NULL )
=======Creating a stored procedure======= Create procedure prc_getBal(@cid int,@bal money output) As Begin Select @bal=bal from customers where cid=@cid End
=====Calling the Stored Procedure====== ------------------ ------------------ using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection("User ID=sa;Password=pass;Initial Catalog=test;Data Source=Personal"); SqlCommand cmd; protected void Page_Load(object sender, EventArgs e) { con.Open(); } protected void BtnSubmit_Click(object sender, EventArgs e) { int cid=Convert.ToInt16(TxtID.Text); cmd=new SqlCommand("prc_getBal",con);
cmd.Parameters.AddWithValue("@cid",cid); cmd.Parameters.AddWithValue("@bal",SqlDbType.Money).Direction=ParameterDirection.Output; cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); Response.Write(cmd.Parameters["@bal"].Value); con.Close(); } }
|