combobox和datagridview的问题
我定义了一个datagridview(没有绑定)和一个combobox,自己在datagridview中构造了一个表(两列),现在从combobox中选择一项,第一列显示combobox的选项,第二列显示从数据库中匹配的值,请问应该如何给第二列赋值呢?private DataSet CreateDataSet()
{
string sqlstr = "Select phone from student where studentid='" + comboBox1.Text + "'";
SqlConnection cn = new SqlConnection("server=(local);integrated security=true;database=studentmanagement;");
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlstr, cn);
DataSet ds = new DataSet();
da.Fill(ds, student);
DataTable dt = new DataTable("student");
DataColumn dc = dt.Columns.Add("id",typeof(string));
dt.Columns.Add("phone", typeof(string));
DataRow dr = dt.NewRow();
dr["id"] = comboBox1.SelectedItem.ToString();
dr["phone"] = ; //这里应该怎么写?
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
//cn.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.dataGridView1.DataSource = CreateDataSet();
this.dataGridView1.DataMember = "student";
}