string strsql = “Data Source=localhost;Initial Catalog=######;Integrated Security=True”;//数据库链接字符串
string sql = “SelectUserName”;//要调用的存储过程名
SqlConnection conStr = new SqlConnection(strsql);//SQL数据库连接对象,以数据库链接字符串为参数
SqlCommand comStr = new SqlCommand(sql, conStr);//SQL语句执行对象,第一个参数是要执行的语句,第二个是数据库连接对象
comStr.CommandType = CommandType.StoredProcedure;//因为要使用的是存储过程,所以设置执行类型为存储过程
//依次设定存储过程的参数
comStr.Parameters.Add("@Param1", SqlDbType.Text).Value = “####”;
conStr.Open();//打开数据库连接
// MessageBox.Show(comStr.ExecuteNonQuery().ToString());//执行存储过程
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(comStr);
DataTable DT=new DataTable ();
SqlDataAdapter1.Fill(DT);
dataGridView1.DataSource = DT;
conStr.Close();//关闭连接
SQL中执行存储过程:
exec AdonIDC.dbo.InsertEMRData ‘1guk’,‘cm’