Create a stored procedure with only input parameters
CREATE PROCEDURE Proc_user
@name varchar (20),
@Password varchar (100)
as
SELECT * FROM Loginuser
Where name like @name
---Create a stored procedure with input and output parameters
CREATE PROCEDURE Proc_usertext
@name varchar (20),
@blog varchar () output
as
Select @blog = blog from loginuser where name = @name
---Create a stored procedure with input and return parameters
Create PROCEDURE ReturnVal
@name varchar (100),
@blog varchar () output
As
Begin
Select @blog = blog from loginuser where name = @name
if (@blog is null)
Set @blog = ' You haven't applied for a blog '
Return execute (@blog)--Conversion of data number type
End
Calls in ASP.
protected void Page_Load (object sender, EventArgs e)
{
DataBind ();
}
private void DataBind ()
{
The notation for stored procedures with input parameters only.
SqlConnection con = new SqlConnection (configurationmanager.connectionstrings["strconnection"]. ConnectionString);
SqlCommand cmd = new SqlCommand ("Proc_user", con);
Cmd.commandtype = CommandType.StoredProcedure;
Cmd. Parameters.addwithvalue ("@name", "l%");
Cmd. Parameters.addwithvalue ("@Password", "lcs9702");
Con. Open ();
SqlDataReader dr = cmd. ExecuteReader ();
Dropdownlist1.datasource = Dr;
Dropdownlist1.datatextfield = "name";
Dropdownlist1.datavaluefield = "use_id";
Dropdownlist1.databind ();
}
private void Textdatabind ()
{
The notation of the stored procedure with input and output parameters.
SqlConnection con = new SqlConnection (configurationmanager.connectionstrings["strconnection"]. ConnectionString);
SqlCommand cmd = new SqlCommand ("Proc_usertext", con);
Cmd.commandtype = CommandType.StoredProcedure;
Cmd. Parameters.Add ("@name", "Love");
Cmd. Parameters.Add ("@blog", sqldbtype.varchar,100);
Cmd. parameters["@blog"]. Direction = ParameterDirection.Output;
Cmd. Parameters.Add (New SqlParameter ("@blog", sqldbtype.varchar,100,parameterdirection.output,false,0,0,string. Empty,datarowversion.default,null));
Cmd.commandtype = CommandType.StoredProcedure;
Con. Open ();
Cmd. ExecuteNonQuery ();
TextBox1.Text = cmd. parameters["@blog"]. Value.tostring ();
Con. Close ();
}
private void Returndatabind ()
{
The notation of the stored procedure with input, which returns parameters.
SqlConnection con = new SqlConnection (configurationmanager.connectionstrings["strconnection"]. ConnectionString);
SqlCommand cmd = new SqlCommand ("ReturnVal", con);
Cmd.commandtype = CommandType.StoredProcedure;
Cmd. Parameters.Add ("@name", "lcs9702");
Cmd. Parameters.Add (New SqlParameter ("@blog", SqlDbType.VarChar, ParameterDirection.Output, False, 0, 0, string. Empty, Datarowversion.default, null));
Cmd.commandtype = CommandType.StoredProcedure;
Con. Open ();
Cmd. ExecuteNonQuery ();
TextBox2.Text = cmd. parameters["@blog"]. Value.tostring ();
Con. Close ();
}
protected void Button1_Click (object sender, EventArgs e)
{
Textdatabind ();
}
protected void button2_click (object sender, EventArgs e)
{
Returndatabind ();
}
ASP. NET call stored Procedure 2