I have a C# ASP.net project that sends a dataset to my connection class where I update the database accordingly.
The dataset I send through is populated with data from 2 tables from my database, thus I used a Join to get the data. (thus the individual update)
Now I have made the changes I want to the dataset and want to Update the database. Both section 1 and 2 of my code works IF only one is run at a time (thus either section 1 or 2 should be commented out).
But when I try and run both, it only updates the database with the first part (no error is thrown, and the code does execute)
Why does this happen? I've also closed and re-opened my connection after the first update to see if that made any difference.
public void udpateCourse(DataSet dataSetEmp)
{
try
{
conn.Open();
//SECTION 1 -- THE FIRST UPDATE
da = new SqlDataAdapter("select * from EthicsManagement", conn);
var builderForTable1 = new SqlCommandBuilder(da);
da.Update(dataSetEmp, "Table");
//SECTION 2 -- THE SECOND UPDATE
da = new SqlDataAdapter("select employeeId, name as [Employee Name] from EmployeeTable", conn);
builderForTable1 = new SqlCommandBuilder(da);
da.Update(dataSetEmp, "Table");
conn.Close();
}
catch (Exception ex)
{
throw new Exception("Problem with the SQL connection " + ex);
}
}
--Update-- What I've Tried
- Closing and opening the connection again
- New Instances of the adapter and builders
- even putting them in a separate method
- Having one query (a join on two tables)