Updating a second DataGridView with Access Data

G

Guest

I have a form with two DataGridView controls. The form has linked to it an
Access database with just two tables. The second table contains unique
"child" data having a one-to-one relationship with each row of the first
table. I am able to display the first table's data in one of the
DataGridView controls - DatgaGridView_A.

What I want to do, but don't know how, is to select a row from the
DataGridView_A and have the data associated with it from the second table
displayed in DataGridView_B. Can someone show me how this is done or give me
an example?
 
D

Doru Roman

This is how I did it in a WEB application, gdCustomers is the main grid,
dgOrders is the detail grid.
Once a selected row is clicked in the Customers grid the detail grid is
filled with the orders.

private void dgCustomers_SelectedIndexChanged(object sender,
System.EventArgs e)

{

DataGridItem item ;

item = dgCustomers.Items[dgCustomers.SelectedIndex];

string mySql = "Select * from Orders Where CustomerID = '" +
item.Cells[1].Text + "'";

SqlCommand comOrdrs = conn.CreateCommand();

comOrdrs.CommandText = mySql;

comOrdrs.CommandType = CommandType.Text;

SqlDataAdapter daOrders = new SqlDataAdapter(comOrdrs);

DataSet dsOrders = new DataSet();

daOrders.Fill(dsOrders);

dgOrders.DataSource = dsOrders;

dgOrders.DataBind();

}
 
G

Guest

What is "conn"?
--
-----------
Thanks,
Steve


Doru Roman said:
This is how I did it in a WEB application, gdCustomers is the main grid,
dgOrders is the detail grid.
Once a selected row is clicked in the Customers grid the detail grid is
filled with the orders.

private void dgCustomers_SelectedIndexChanged(object sender,
System.EventArgs e)

{

DataGridItem item ;

item = dgCustomers.Items[dgCustomers.SelectedIndex];

string mySql = "Select * from Orders Where CustomerID = '" +
item.Cells[1].Text + "'";

SqlCommand comOrdrs = conn.CreateCommand();

comOrdrs.CommandText = mySql;

comOrdrs.CommandType = CommandType.Text;

SqlDataAdapter daOrders = new SqlDataAdapter(comOrdrs);

DataSet dsOrders = new DataSet();

daOrders.Fill(dsOrders);

dgOrders.DataSource = dsOrders;

dgOrders.DataBind();

}
 
D

Doru Roman

conn is the connection instance
SQLConnection con = new SQLConnection(....)


Steve Teeples said:
What is "conn"?
--
-----------
Thanks,
Steve


Doru Roman said:
This is how I did it in a WEB application, gdCustomers is the main grid,
dgOrders is the detail grid.
Once a selected row is clicked in the Customers grid the detail grid is
filled with the orders.

private void dgCustomers_SelectedIndexChanged(object sender,
System.EventArgs e)

{

DataGridItem item ;

item = dgCustomers.Items[dgCustomers.SelectedIndex];

string mySql = "Select * from Orders Where CustomerID = '" +
item.Cells[1].Text + "'";

SqlCommand comOrdrs = conn.CreateCommand();

comOrdrs.CommandText = mySql;

comOrdrs.CommandType = CommandType.Text;

SqlDataAdapter daOrders = new SqlDataAdapter(comOrdrs);

DataSet dsOrders = new DataSet();

daOrders.Fill(dsOrders);

dgOrders.DataSource = dsOrders;

dgOrders.DataBind();

}


Steve Teeples said:
I have a form with two DataGridView controls. The form has linked to it
an
Access database with just two tables. The second table contains unique
"child" data having a one-to-one relationship with each row of the
first
table. I am able to display the first table's data in one of the
DataGridView controls - DatgaGridView_A.

What I want to do, but don't know how, is to select a row from the
DataGridView_A and have the data associated with it from the second
table
displayed in DataGridView_B. Can someone show me how this is done or
give
me
an example?
 
G

Guest

Thank you for the direction. My issue is now resolved.
--
-----------
Thanks,
Steve


Doru Roman said:
conn is the connection instance
SQLConnection con = new SQLConnection(....)


Steve Teeples said:
What is "conn"?
--
-----------
Thanks,
Steve


Doru Roman said:
This is how I did it in a WEB application, gdCustomers is the main grid,
dgOrders is the detail grid.
Once a selected row is clicked in the Customers grid the detail grid is
filled with the orders.

private void dgCustomers_SelectedIndexChanged(object sender,
System.EventArgs e)

{

DataGridItem item ;

item = dgCustomers.Items[dgCustomers.SelectedIndex];

string mySql = "Select * from Orders Where CustomerID = '" +
item.Cells[1].Text + "'";

SqlCommand comOrdrs = conn.CreateCommand();

comOrdrs.CommandText = mySql;

comOrdrs.CommandType = CommandType.Text;

SqlDataAdapter daOrders = new SqlDataAdapter(comOrdrs);

DataSet dsOrders = new DataSet();

daOrders.Fill(dsOrders);

dgOrders.DataSource = dsOrders;

dgOrders.DataBind();

}


I have a form with two DataGridView controls. The form has linked to it
an
Access database with just two tables. The second table contains unique
"child" data having a one-to-one relationship with each row of the
first
table. I am able to display the first table's data in one of the
DataGridView controls - DatgaGridView_A.

What I want to do, but don't know how, is to select a row from the
DataGridView_A and have the data associated with it from the second
table
displayed in DataGridView_B. Can someone show me how this is done or
give
me
an example?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top