C#调用存储过程总结

存储过程在数据库的数据处理中起到很大的作用,避免了很多重复性工作,使数据的处理效率提高。而存储过程也经常在程序中调用,它的调用过程如下:


例子:
Conn.Open();
SqlCommand myCommand = Conn.CreateCommand(); //步骤一
myCommand.CommandType = CommandType.StoredProcedure; //步骤二
myCommand.CommandText = "SfcReport_sp"; //步骤三
myCommand.Parameters.Add("@Type", SqlDbType.Text).Value = SpTypeStr; //步骤四
myCommand.Parameters.Add("@Model", SqlDbType.Text).Value = ""; //步骤五
myCommand.Parameters.Add("@Startdate", SqlDbType.DateTime).Value = null; //步骤六
myCommand.Parameters.Add("@Enddate", SqlDbType.DateTime).Value = null; //步骤七
myCommand.Parameters.Add("@Productionline", SqlDbType.Text).Value = ProductionlineStr; //步骤八
myCommand.ExecuteReader(); //步骤九



说明:
Conn:指定义的数据库连接对象;
步骤一:新建数据库命令对象,并用数据库连接对象初始化这个命令对象;
步骤二:设置执行语句类型为存储过程;
步骤三:指定存储过程名字;
步骤四:给存储过程的输入参数@Type赋值;
步骤五到八:同步骤四;
步骤九:执行存储过程。

猜你喜欢

转载自blog.csdn.net/jimson_zhu/article/details/79972442