C#调用存储过程
1、不带参数的存储过程
string str = ConfigurationManager.ConnectionStrings["FK"].ConnectionString;
SqlConnection conn = new SqlConnection(str);
conn.Open();
if (radioButton1.Checked)
{
radioButton1.ForeColor = Color.Red;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand();
//da.selectCommand.Connection = conn;
da.SelectCommand.CommandText = "Pro_GetJLPFStatus";
da.SelectCommand.CommandType= CommandType.StoredProcedure;
MessageBox.Show("已更新!");
radioButton1.ForeColor = Color.Black;
}
conn.Close();
2、带参数的存储过程
string str = ConfigurationManager.ConnectionStrings["FK"].ConnectionString;
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = new SqlCommand("wf_delete", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@guid", Guid.NewGuid()));
cmd.Parameters["@guid"].Value = this.textBox4.Text;
if (textBox4.Text.Trim() == String.Empty)
{
MessageBox.Show("执行此操作需输入KeyValue");
};
cmd.ExecuteNonQuery();
MessageBox.Show("该表单流程信息已清空,状态已改为“新增”,如有问题请与系统管理员联系!");
conn.Close();