我有DataGridView,它由三列Profname, Profcharges and Profduedate
填充。我已将Profname Column转换为一个comboBox,它由数据库中的所有Profnames填充。当任何Profname选择表格comboxBox时,我想自动填写Profcharges和Profduedate值。
我的代码是:
try{
SqlConnection con = new SqlConnection(@"Data Source=AFZAL\SQLEXPRESS;Initial Catalog=GIMS_LabInfo;Integrated Security=True");
con.Open();
SqlCommand sc = new SqlCommand("SELECT PROFNAME, PROFCHARGES, PROFDUEDATE FROM PROFNAMES$", con);
SqlDataReader reader;
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("TEST NAME", typeof(string));
dt.Load(reader);
Column1.ValueMember = "Profname";
Column1.DisplayMember = "Profname";
Column1.DataSource = dt;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}