M
Marc
Hello.
I have two tables in a dataset which have both been updated, i am aware
that i cannot use the commandbuilder to update tow tables with a join,
and i obviously get referential integrity errors when i try to update
them one at a time. I am aware i need to roll my own update routine:
has anyone done this before and have any pointers? I can find very
little regarding this on groups and the internet. My first attempt is:
<code>
try
{
string updateCmd;
updateCmd = "UPDATE tblTimes ";
updateCmd += "INNER JOIN tblActivityTimes ";
updateCmd += "ON tblTimes.TimeID = tblActivityTimes.TimeID ";
updateCmd += "SET tblActivityTimes.TimeID = @newTimeID, ";
updateCmd += "tblTimes.TimeID = @timeid, tblTimes.[Day] = @day, ";
updateCmd += "tblTimes.[Date] = @date, tblTimes.Start = @start, ";
updateCmd += "tblTimes.[End] = @end";
//add parameters for each data object
cmdBuild = new OleDbCommandBuilder(oDA);
cmdBuild.QuotePrefix = "[";
cmdBuild.QuoteSuffix = "]";
oDA.SelectCommand = new OleDbCommand(sqlTimes, oConn);
oDA.SelectCommand.Connection = dbConnect(db.connString());
oDA.SelectCommand.CommandText = (string)ViewState["sqlTimes"];
oDA.UpdateCommand = new OleDbCommand(updateCmd, oConn);
oDA.UpdateCommand.Connection = dbConnect(db.connString());
oDA.UpdateCommand.CommandText = updateCmd;
oDA.Update(ds,"tblTimes");
}
catch(Exception exc)
{
Response.Write(exc);
}
</code>
but i still get the OleDbException:
<error>
System.Data.OleDb.OleDbException: The record cannot be deleted or
changed because table 'tblActivityTimes' includes related records. at
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping) at
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable) at ASP.proforma_aspx.mergeDtNew() in
C:\Inetpub\wwwroot\physical_activity\admin\proforma.aspx:line 711
</error>
Any help would be appreciated!
cheers,
marc
I have two tables in a dataset which have both been updated, i am aware
that i cannot use the commandbuilder to update tow tables with a join,
and i obviously get referential integrity errors when i try to update
them one at a time. I am aware i need to roll my own update routine:
has anyone done this before and have any pointers? I can find very
little regarding this on groups and the internet. My first attempt is:
<code>
try
{
string updateCmd;
updateCmd = "UPDATE tblTimes ";
updateCmd += "INNER JOIN tblActivityTimes ";
updateCmd += "ON tblTimes.TimeID = tblActivityTimes.TimeID ";
updateCmd += "SET tblActivityTimes.TimeID = @newTimeID, ";
updateCmd += "tblTimes.TimeID = @timeid, tblTimes.[Day] = @day, ";
updateCmd += "tblTimes.[Date] = @date, tblTimes.Start = @start, ";
updateCmd += "tblTimes.[End] = @end";
//add parameters for each data object
cmdBuild = new OleDbCommandBuilder(oDA);
cmdBuild.QuotePrefix = "[";
cmdBuild.QuoteSuffix = "]";
oDA.SelectCommand = new OleDbCommand(sqlTimes, oConn);
oDA.SelectCommand.Connection = dbConnect(db.connString());
oDA.SelectCommand.CommandText = (string)ViewState["sqlTimes"];
oDA.UpdateCommand = new OleDbCommand(updateCmd, oConn);
oDA.UpdateCommand.Connection = dbConnect(db.connString());
oDA.UpdateCommand.CommandText = updateCmd;
oDA.Update(ds,"tblTimes");
}
catch(Exception exc)
{
Response.Write(exc);
}
</code>
but i still get the OleDbException:
<error>
System.Data.OleDb.OleDbException: The record cannot be deleted or
changed because table 'tblActivityTimes' includes related records. at
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping) at
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable) at ASP.proforma_aspx.mergeDtNew() in
C:\Inetpub\wwwroot\physical_activity\admin\proforma.aspx:line 711
</error>
Any help would be appreciated!
cheers,
marc