SCM

[#1010533] Data Adapter Update corrupts DataTable object.

View Trackers | Bugs | Download .csv | Monitor

Date:
2008-12-16 00:58
Priority:
3
State:
Open
Submitted by:
Jason Evans (jasoev)
Assigned to:
Nobody (None)
Npgsql Version:
2.0
Category:
Group:
Resolution:
None
Summary:
Data Adapter Update corrupts DataTable object.

Detailed description

In the following C# method, if you observe the dataTable before and after the last line "dataAdapter.Update(dataTable)", you'll see that the dataTable is modified and cannot be reused again by this method. I've observed that a column was added to the dataTable, with a name derived from the sql (weird).

Parameter example:
sql = "select * from add_stuff(:item1, :item2)";
tableParameterNames = new string[] { "item1", "item2" };
dataTable.Columns[0].ColumnName = "item1";
dataTable.Columns[1].ColumnName = "item2";



void AddDataTableToDatabase(string sql, IList<string> tableParameterNames, DataTable dataTable)
{
using (DbDataAdapter dataAdapter = _CreateDataAdapter())
using (DbCommand command = CreateCommand())
{
command.Connection = _Connection;
dataAdapter.InsertCommand = command;

int parameterIndex = 0;
foreach (string aTableParameterName in tableParameterNames)
{
DataColumn column = dataTable.Columns[aTableParameterName];
//Add the parameter.
DbParameter dbParameter = CreateParameter();
dbParameter.ParameterName = string.Format(":{0}", column.ColumnName);
dbParameter.DbType = ConvertToDbType(column.DataType); dataAdapter.InsertCommand.Parameters.Add(dbParameter);
dataAdapter.InsertCommand.Parameters[parameterIndex].SourceColumn = column.ColumnName;

++parameterIndex;
}

dataAdapter.InsertCommand.CommandText = sql;
dataAdapter.Update(dataTable);
}
}

Followup

Message
Date: 2008-12-17 01:48
Sender: Josh Cooley

Can you post the full sample code? A large part of data adapters is implemented by the .NET framework. Npgsql doesn't directly change DataTables.

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge