c#调用sql存储过程的步骤

来源:互联网 发布:不需要的战争知乎 编辑:程序博客网 时间:2024/05/17 22:47


            String conn3 = "Data Source=WEINIU;Initial Catalog=sde;Persist Security Info=True;User ID=sa;Password=m";
            SqlConnection connection3 = new SqlConnection(conn3);
            string sql3 = "PR_GENXINJIUQISI";//过程名字             
            SqlCommand cmd3 = new SqlCommand();//执行对象 
            cmd3.CommandType = CommandType.StoredProcedure;//设置解释方法为存储过程             
            cmd3.CommandText = sql3;//设置执行语句 
            cmd3.Connection = connection3;//执行的链接 对象 
            connection3.Open();//打开数据库 
            int count = (int)cmd3.ExecuteNonQuery();//返回受影响行数             
            if (count > 0)
            {
                MessageBox.Show("执行成功!");
            }
            connection3.Close();//关闭 
0 0