I'm working on a vet app, using C# and SQL. When I have access to the client history, it fills my pacient datagridview. I would like to know how to fill the clinic history datagridview from the pacient datagridview while I have selected the rows of the pacient. Already made the ClearSelection() from load to deselect any pacient, but I tried to make the SelectedRow event, and nothing happens on the clinic history datagridview.
If needed, I can put the code or pictures later.
PS: clinic history table has foreign key linked to pacient table.
EDIT: Here is the code I wrote. GetData gets the pacient's table and GetData2 the clinichistory's table.
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);
}
}
//Here is the part that confuses me, since the pacient table works perfectly, but not so the clinichistory table. The following works with a client search, which returns the pacient owned by the client
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 + "%'");
}
}
//After this, Idk how to continue to make it work. Bindingsource17 is the datagridview for pacients, and Bindingsource18 the same but for clinichistory.
Thank you very much.
PS: I have a few weeks coding experiencie, so sorry if it looks like a complete mess. I do what I can.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…