查询:依据文本条件执行存储过程
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("server =.; integrated security = sspi; database = 学生管理");
SqlCommand comm = new SqlCommand("coursename",conn);
comm.CommandType = CommandType.StoredProcedure;
SqlParameter dat = new SqlParameter("@cname",SqlDbType.VarChar,20);
dat.Value = this.textname.Text;
comm.Parameters.Add(dat);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds);
dataGrid1.DataSource = ds.Tables[0];
conn.Close();
}

浙公网安备 33010602011771号