这里先列出使用正常的sql语句访问的例子
数据库连接字符串
string connectionString = "Data Source= (local);
Initial Catalog=ICHSLocalSystemDB;
User ID=sa;
Password=ma123456"
依次对应 服务器,数据库,用户名,密码
SqlConnection con = new SqlConnection(connectingString);
string query = "select * from a"
SqlCommand comm = new SqlCommand(query, con);
comm.Open();
生成数据库连接,和数据库请求之后打开数据库
使用存储过程和sql 在 过程上是一致的,
SqlConnection con = new SqlConnection(connectingString);
string storedProcName = "AAA";
SqlCommand comm = new SqlCommand(storedProcName, con);
SqlParameter par = new SqlParameter("@name","lili");
IDataParameter[] pars = new IDataParameter{par};
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.AddRange(pars);
原来写入sql语句的地方 写入存储过程的名字
设置comm类型为存储过程类型
写入存储过程需要用到的参数
这些参数要有自己的类型,并不能统统使用"XXX"的形式,如果存储过程中使用 int 或 float 我们在传参的时候也要写入对应的类型