我有 2 个数据网格需要显示 2 个表中的数据,我为每个数据网格使用了 2 个加载表来显示数据。
public diagnosechipcomplainprint()
{
InitializeComponent();
load_table();
}
void load_table()
{
string query = "Select HospitalRecordNo,concat(Patient_Fname, ' ', Patient_Mname, ' ',Patient_Lname) as 'Patient Name',Age,Gender,DateOfBirth,Email,PatientContact from patientinfo;";
MySqlConnection con = new MySqlConnection(connection);
MySqlCommand com = new MySqlCommand(query, con);
try
{
MySqlDataAdapter sd = new MySqlDataAdapter();
sd.SelectCommand = com;
DataTable dba = new DataTable();
sd.Fill(dba);
BindingSource bs = new BindingSource();
bs.DataSource = dba;
dataGridView1.DataSource = bs;
sd.Update(dba);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void load_table2()
{
string query2 = "Select VisitNo, HospitalRecordNo, DateOfVisit from visit_details where HospitalRecordNo = '" + recordno.Text + "';";
MySqlConnection con = new MySqlConnection(connection);
MySqlCommand com = new MySqlCommand(query2, con);
try
{
MySqlDataAdapter sd = new MySqlDataAdapter();
sd.SelectCommand = com;
DataTable dba = new DataTable();
sd.Fill(dba);
BindingSource bs = new BindingSource();
bs.DataSource = dba;
dataGridView2.DataSource = bs;
sd.Update(dba);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
当我在第一个数据网格上单击单元格时,数据网格中的数据将显示在标签中,但是当我单击第二个数据网格时,它显示错误。
这是我在 Cellclick 数据网格视图 2 中使用的代码。我希望你能帮助我。谢谢
aluckdog
慕丝7291255
相关分类