日期:2014-05-17 浏览次数:20901 次
//绑定数据的方法
private void GetDB(string str)
{
//SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
//con.Open();
//SqlDataAdapter sdr = new SqlDataAdapter();
//SqlCommand cmd = new SqlCommand(str, con);
//sdr.SelectCommand = cmd;
//DataSet ds = new DataSet();
con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
con.Open();
sdr = new SqlDataAdapter();
sdb = new SqlCommandBuilder(sdr);
cmd = new SqlCommand(str,con);
sdr.SelectCommand = cmd;
ds = new DataSet();
sdr.Fill(ds);
//向gridview中添加列
DataGridViewTextBoxColumn col_txb_Id = new DataGridViewTextBoxColumn();
col_txb_Id.HeaderText = "课程编号";
col_txb_Id.DataPropertyName = "cno";
dataGridView1.Columns.Add(col_txb_Id);
DataGridViewTextBoxColumn col_txb_Name = new DataGridViewTextBoxColumn();
col_txb_Name.HeaderText = "课程名";
col_txb_Name.DataPropertyName = "cname";
dataGridView1.Columns.Add(col_txb_Name);
DataGridViewTextBoxColumn col_txb_Score = new DataGridViewTextBoxColumn();
col_txb_Score.HeaderText = "课程学分";
col_txb_Score.DataPropertyName = "ccredit";
dataGridView1.Columns.Add(col_txb_Score);
Da