string connstring = @"Data Source=localhost;Initial Catalog=Northwind;uid=sa;pwd=123456"; 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存储过程中的参数。 -------------- CommandType为Procedure 然后把Sql语句 改为存储过程的名称 (责任编辑:admin) |