Wednesday, March 7, 2012

DataAdapter.Update does not work with DataSet.Merge!!!!

Hi Everybody,
I am Updating server database with data from client database, I am using mySQL Ver 4.1, I am unable to do that. What should I do to change the codes to make it work? I have also another method that do the opposite data from server updates the database on client side. I need help. There is no change in records of target database. I have saw some topics here at this forum. The problem is Connection to server database is ok, but when odAdapter.Update(ds,"<tablename>"); executes it returns value of 0 and on changes made to server database, it should have 12 rows. Advanced Thanks.


Code:

public int UpdateServerTable1(DataTable dtObj)
{
DataSet ds = new DataSet();
int iRes = 0;
try
{
this.sqlTextServer = "Select * From <tablename>";

OdbcDataAdapter odAdapter = new OdbcDataAdapter(this.sqlTextServer,this.odServerConn );

odAdapter.Fill(ds,"<tablename>");

ds.Merge(dtObj,true,MissingSchemaAction.Ignore);

OdbcCommandBuilder cmdBuild = new OdbcCommandBuilder(odAdapter);

iRes = odAdapter.Update(ds,"<tablename>");
}
catch (Exception ex)
{
ds.RejectChanges();
}
return iRes;
}


Regards,
denpsia

Hi,

Check the state of every row. Determine if the RowState of the rows in dtObj was changed to Unchanged. also try inspecting your UpdateCommand and InsertCommand see if the command builder generated the correct sql syntax...

cheers,

Paul June A. Domag

No comments:

Post a Comment