Here is some code that results in the error message when using
transactions with datasets.
It's more informative than my last message.
The code works with SQL Server 2005 and with SQLite.
FbTransaction transaction = null;
using (FbConnection myConnection = new
FbConnection(conStrbuilder.ConnectionString))
{
myConnection.Open();
FbCommand command = myConnection.CreateCommand();
transaction = myConnection.BeginTransaction();
myFbDataAdapter.AcceptChangesDuringUpdate = false;
command.Connection = myConnection;
command.Transaction = transaction;
try
{
myFbDataAdapter.MissingSchemaAction =
MissingSchemaAction.AddWithKey;
myFbDataAdapter.SelectCommand = new FbCommand("SELECT resid,
firstname, lastname FROM resident_tbl", myConnection);
myFbDataAdapter.UpdateCommand = new FbCommand("UPDATE
resident_tbl SET firstname = ?, lastname = ? WHERE resid = ?",
myConnection);
myFbDataAdapter.UpdateCommand.Parameters.Add("@firstname",
FbDbType.VarChar, 50, "firstname");
myFbDataAdapter.UpdateCommand.Parameters.Add("@lastname",
FbDbType.VarChar, 50, "lastname");
myFbDataAdapter.UpdateCommand.Parameters.Add("@resid",
FbDbType.Decimal, 9, "resid").SourceVersion = DataRowVersion.Original;
myFbDataAdapter.Fill(myDataSet, "resident_tbl");
DataTable residentDataTable = myDataSet.Tables["resident_tbl"];
//set primary key property of the datatable
residentDataTable.PrimaryKey = new DataColumn[]
{
residentDataTable.Columns["resid"]
};
//find the row to update
DataRow myEditDataRow = residentDataTable.Rows.Find(resid);
myEditDataRow["firstname"] = txtFirstname.Text;
myEditDataRow["lastname"] = txtLastname.Text;
//write to database
myFbDataAdapter.Update(residentDataTable);
transaction.Commit();
myDataSet.AcceptChanges();
}
catch (Exception ex)
{
transaction.Rollback();
}
}
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider