M
Malenfant
I've recently made the switch to C# from vb6 and although loving it
I'm plagued by concurrency problems when updating new recordsets. I've
solved prior problems by using the FillSchema command and changed the
database to make things harder to fall apart but I'm still having the
same core problem.
Whenever I create a new datarow and add it to the table the very next
edit on that same datarow causes a concurrency violation. I've scoured
the net for answers but none have illuminated the problem.
To making helping me as easy as possible I've created a stripped down
example of the problem in a seperate project, this contains just 2
buttons, one to create the new record, one to change the name column.
The database behind it is Access 2000 in this case and the underlying
table could be as simple as just ID,name.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace concurrancyError
{
public partial class Form1 : Form
{
private string customerConnectionString;
private OleDbConnection customerConnect;
private string billingrunSQL;
private OleDbDataAdapter billingRunAdapter;
public DataSet billingRuns;
public DataRow billingRunDataRow;
public Form1()
{
InitializeComponent();
customerConnectionString = "Provider=Microsoft.Jet.OLEDB.
4.0;Data Source = c:\\testing\\test.mdb";
customerConnect = new
OleDbConnection(customerConnectionString);
billingrunSQL = "SELECT * from billingrun";
billingRunAdapter = new OleDbDataAdapter(billingrunSQL,
customerConnect);
OleDbCommandBuilder billingRunBuilder = new
OleDbCommandBuilder(billingRunAdapter);
billingRuns = new DataSet();
billingRunAdapter.FillSchema(billingRuns,
SchemaType.Mapped, "billingrun");
billingRunAdapter.Fill(billingRuns, "billingrun");
}
private void button1_Click(object sender, EventArgs e)
{
billingRunDataRow =
billingRuns.Tables["billingrun"].NewRow();
billingRuns.Tables["billingrun"].Rows.Add(billingRunDataRow);
billingRunDataRow["name"] = "pre foo";
billingRunAdapter.Update(billingRuns.Tables["billingrun"]);
}
private void button2_Click(object sender, EventArgs e)
{
billingRunDataRow["name"] = "foo";
//This is where it crashes.
billingRunAdapter.Update(billingRuns.Tables["billingrun"]);
}
}
}
Any help would be greatly appreciated.
I'm plagued by concurrency problems when updating new recordsets. I've
solved prior problems by using the FillSchema command and changed the
database to make things harder to fall apart but I'm still having the
same core problem.
Whenever I create a new datarow and add it to the table the very next
edit on that same datarow causes a concurrency violation. I've scoured
the net for answers but none have illuminated the problem.
To making helping me as easy as possible I've created a stripped down
example of the problem in a seperate project, this contains just 2
buttons, one to create the new record, one to change the name column.
The database behind it is Access 2000 in this case and the underlying
table could be as simple as just ID,name.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace concurrancyError
{
public partial class Form1 : Form
{
private string customerConnectionString;
private OleDbConnection customerConnect;
private string billingrunSQL;
private OleDbDataAdapter billingRunAdapter;
public DataSet billingRuns;
public DataRow billingRunDataRow;
public Form1()
{
InitializeComponent();
customerConnectionString = "Provider=Microsoft.Jet.OLEDB.
4.0;Data Source = c:\\testing\\test.mdb";
customerConnect = new
OleDbConnection(customerConnectionString);
billingrunSQL = "SELECT * from billingrun";
billingRunAdapter = new OleDbDataAdapter(billingrunSQL,
customerConnect);
OleDbCommandBuilder billingRunBuilder = new
OleDbCommandBuilder(billingRunAdapter);
billingRuns = new DataSet();
billingRunAdapter.FillSchema(billingRuns,
SchemaType.Mapped, "billingrun");
billingRunAdapter.Fill(billingRuns, "billingrun");
}
private void button1_Click(object sender, EventArgs e)
{
billingRunDataRow =
billingRuns.Tables["billingrun"].NewRow();
billingRuns.Tables["billingrun"].Rows.Add(billingRunDataRow);
billingRunDataRow["name"] = "pre foo";
billingRunAdapter.Update(billingRuns.Tables["billingrun"]);
}
private void button2_Click(object sender, EventArgs e)
{
billingRunDataRow["name"] = "foo";
//This is where it crashes.
billingRunAdapter.Update(billingRuns.Tables["billingrun"]);
}
}
}
Any help would be greatly appreciated.