This article illustrates the comparison of SQL Server with stored procedures from several perspectives.
Why do ① use stored procedures?
Because it executes faster than SQL statements.
What is the ② stored procedure?
With a bunch of SQL statements, you can also execute an SQL statement based on a condition.
③ to one of the simplest stored procedures:
CREATE PROCEDURE dbo.testProcedure_AX
AS
select userID from
USERS order by userid desc
Note: Dbo.testprocedure_ax is the name of the stored procedure you created, you can change it to: Axzhz and so on, do not conflict with the keyword on the line. As the following is a SQL statement, do not write SQL statements, please avoid.
④ How to call this stored procedure in asp.net:
public static string GetCustomerCName
(ref ArrayList arrayCName,ref ArrayList arrayID)
{
SqlConnection con=ADConnection.createConnection();
SqlCommand cmd=new SqlCommand("testProcedure_AX",con);
cmd.CommandType=CommandType.StoredProcedure;
con.Open();
try
{
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
if(dr[0].ToString()=="")
{
arrayCName.Add(dr[1].ToString());
}
}
con.Close();
return "OK!";
}
catch(Exception ex)
{
con.Close();
return ex.ToString();
}
}