string connstring = @"Data Source=localhost;Initial Catalog=Northwind;uid=sa;pwd="; SqlConnection conn = new SqlConnection(connstring); conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure;//设置cmd的类型为存储过程 cmd.CommandText = "CustOrderHist"; cmd.Connection = conn; SqlParameter pCustomerID = new SqlParameter(); pCustomerID.ParameterName = "@CustomerID"; pCustomerID.SqlDbType = SqlDbType.NChar; pCustomerID.Value = "ALFKI"; cmd.Parameters.Add(pCustomerID); CustOrderHist:存储过程名称,@CustomerID存储过程中的参数。
如何在C#中调用存储过程
最新推荐文章于 2024-02-29 20:08:48 发布