System.Data.DBConcurrencyException was unhandled

  • Thread starter Thread starter Cub71
  • Start date Start date
C

Cub71

I am using Microsift Visual C# 2005 Express Edition and SQL Server 2005
Express Edition.
I have created a few tables in the IDE.

When I run my program in debug run the
dataAdapter.update(dataset.table), and the tables are empty, i get the
DBConcurrencyException (Message="Concurrency violation: the
UpdateCommand affected 0 of the expected 1 records.").

This only happends when the tables are empty. If I at designtime
populates the tables with one row each, this doesn't happend.

Any ideas on this?
 
The dataset is a typed dataset created with drag and drop in the IDE.


private void Form1_Load(object sender, EventArgs e)
{
daemployees = new SqlDataAdapter("SELECT * FROM employees",
connString);
SqlCommandBuilder cmdBldremployees = new
SqlCommandBuilder(daemployees);
daemployees.FillSchema(myCompanyDataSet1,
SchemaType.Source, "employees");
daemployees.Fill(myCompanyDataSet1, "employees");
}


private void createEmployees(int number)
{
for (int i = 1; i <= number; i++)
{
DataRow EmployeesRow =
myCompanyDataSet1.Employees.NewRow();
int newEmplNo = 37000 + totalnumberEmployees;
EmployeesRow["EmplNo"] = newEmplNo;
EmployeesRow["ReadyAt"] = "01.01.2006 0:00";

if (totalnumberEmployees < 3)
{
EmployeesRow["ReadyFrom"] = "LYR";
}
else if (totalnumberEmployees < 6)
{
EmployeesRow["ReadyFrom"] = "TOS";
}

else if (totalnumberEmployees < 8)
{
EmployeesRow["ReadyFrom"] = "ALF";
}

else if (totalnumberEmployees < 9)
{
EmployeesRow["ReadyFrom"] = "BDU";
}
else
{
EmployeesRow["ReadyFrom"] = "OSL";
}

totalnumberEmployees++;

myCompanyDataSet1.Employees.Rows.Add(EmployeesRow);

}

daEmployees.Update(myCompanyDataSet1.Employees); // This
is where it fails
updateLabels();
}
 
The only thing I can think of is reconfigure the dataset. You open the
Dataset then right click the buttom part then you should see something like
Configure Dataset or so.

chanmm
 
Back
Top