i want to update tables for my database when i update one record from a table the second table must be updated automatically.
below is update button for my first table
private void btn_Update_Click(object sender, EventArgs e)
{
try
{
System.Data.DataTable dt2;
dt2 = ds.Tables["tblForce_N"];
this.assetdg.BindingContext[dt2].EndCurrentEdit();
this.da.Update(dt2);
MessageBox.Show("Data Update successfull", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
here is update button for my second table
private void button1_Click(object sender, EventArgs e)
{
try
{
System.Data.DataTable dt2;
dt2 = ds2.Tables["tblComp"];
this.assetdg.BindingContext[dt2].EndCurrentEdit();
this.da2.Update(dt2);
MessageBox.Show("Data Update successfull", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
when i click update from one table i want the second table to be updated automatically ,i'm using datagridview not text boxes to enter records.
Madito KevinPosted Apr 28, 2015, 12:29 AM
Manoj BhoirPosted Apr 27, 2015, 2:13 AM
If you want to update your second table on updation of first table, you already written code for first and second table on Button1 and btn_Update so you can directly call button1_Click(this, e) on btn_update_click event or else you can write another method which will update your sub tables and call that method on your update button click event.
For example :
private void btnUpdate_Click(object sender, EventArgs e)
{
//Your Main table updated code goes here.
// Here you can call other button click or method which contains sub table updation code.
}
Sibeesh VenuPosted Apr 27, 2015, 1:39 AM
Can you use triggers ? If yes find out the basics here.
http://www.aspsnippets.com/Articles/Simple-Insert-Update-and-Delete-Triggers-in-SQL-Server-with-example.aspx
Please up vote and accept if it helps you.
Kindest Regards
Sibeesh Venu
www.sibeeshpassion.com