简单的存储过程调用demo
时间:2010-11-03 来源:Earloye
Use score 数据库
go
Create procedure aaaa 存储过程名
@sname nvarchar(20) 参数
as
select * from s where sname=@sname
在VS中调用
private void button1_Click(object sender, EventArgs e)
{
string strcon = "server=.\\sqlexpress;database=score;Trusted_Connection=SSPI";
SqlConnection cn = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "aaaa"; 存储过程名
cmd.CommandType = CommandType.StoredProcedure; 类型
SqlParameter pt = new SqlParameter("@sname", "阿迪"); 获取参数
cmd.Parameters.Add(pt);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(); 读取
if (rdr.Read())
{
MessageBox.Show(rdr[0].ToString() + rdr[1].ToString() + rdr[2].ToString()+rdr[3].ToString ());
}
}
最后结果是