【发布时间】:2020-10-14 01:15:14
【问题描述】:
我正在使用 C# 和 SQL 开发一个兽医应用程序。当我可以访问客户端历史记录时,它会填满我的 pacient datagridview。我想知道如何在我选择了病人的行时从病人的数据网格视图中填充临床历史数据网格视图。已经将 ClearSelection() 从加载中取消选择任何患者,但我尝试进行 SelectedRow 事件,但诊所历史数据网格视图上没有任何反应。 如果需要,我可以稍后放代码或图片。
PS:临床病历表有外键链接到病人表。
编辑:这是我写的代码。 GetData 获取患者表,GetData2 获取临床历史表。
private void GetData(string selectCommand)
{
try
{
dataAdapter = new SqlDataAdapter(selectCommand, connString);
table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource17.DataSource = table;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void GetData2(string selectCommand)
{
dataGridView3.DataSource = null;
try
{
dataAdapter = new SqlDataAdapter(selectCommand, connString);
table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource18.DataSource = table;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
//这是让我感到困惑的部分,因为 pacient 表完美地工作,但临床历史表却不是这样。以下适用于客户端搜索,它返回客户端拥有的 pacient
private void button12_Click_1(object sender, EventArgs e)
{
Form7 Buscarcli = new Form7();
Buscarcli.TransfEvent += frm_TransfEvent;
Buscarcli.ShowDialog();
dataGridView2.DataSource = bindingSource17;
if (lblID.Text != null)
{
GetData("Select * from Pacientes where id_pacientes like '%" + lblID.Text + "%'");
}
}
//在这之后,Idk如何继续使它工作。 Bindingsource17 是用于患者的数据网格视图,Bindingsource18 相同,但用于临床历史。
非常感谢。 PS:我有几个星期的编码经验,如果看起来一团糟,很抱歉。我尽我所能。
【问题讨论】:
-
请向我们提供一些代码,显示您的尝试。如果您还没有阅读,请花点时间阅读how to ask。
标签: c# sql datagridview