Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to update sql database through c#

Status
Not open for further replies.

markyjj01

Programmer
Feb 10, 2008
5
Can someone please help me with the following I am getting a mappings exception as follows: 'Update unable to find TableMapping['MovTable1'] or DataTable 'MovTable1'.

This happens when I try to save the changes made when I have entered details
onto a datagrid which is linked to a sql database. The dataset I create is
called Movset1 and I fill this with the table from sql called MovTable1. But
when I use the following ' F1.MovAdapt.Update(F1.Movset1, "MovTable1")' this
cuases the TableMapping exception.

the updated C# code I am now using is below....thanks for any help

//code when loading data grid//
private void button3_Click(object sender, System.EventArgs e)
{ Form3 F3 = new Form3();
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(MovAdapt);
MovAdapt.TableMappings.Add("MovMapping", "MovTable1");
Mcon.Open();
Movcmd.CommandText = "SELECT * FROM MovTable1";
MovAdapt.SelectCommand = Movcmd;
MovAdapt.Fill(Movset1, "MovTable1");
F3.dataGrid1.DataSource = Movset1;
F3.Show();
}

-----------------------------
//code behind the save button//

private void button1_Click(object sender, System.EventArgs e)
{
F1.MovAdapt.Update(F1.Movset1, "MovTable1");
Form1.Mcon.Close();

}
 
Are you using 1 SqlAdapter (to select and update)? Is the 'MovAdapt' in button3_Click the same object as 'F1.MovAdapt' in button1_Click?

|| ABC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top