查询:依据文本条件执行存储过程

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();


  }

posted @ 2007-04-20 08:23  jun.ma  阅读(133)  评论(0)    收藏  举报