Reputation: 5182
I'm using a DataAdapter
and DataTable
to edit/add data in a Oracle db table, using ODP.NET provider.
DataSet ds = new DataSet("report");
DataTable dt = new DataTable("report");
adptr = new OracleDataAdapter();
string myCmd = "select * from report";
OracleCommand _cmd = new OracleCommand(myCmd, myDbConnection);
adptr.SelectCommand = _cmd;
adptr.Fill(dt);
ds.Tables.Add(dt);
After this i alter the data in the data table, by binding it to a grid and editing it and save like this :
OracleCommandBuilder _cmdBld = new OracleCommandBuilder(adptr);
adptr.Update(ds, "report");
Everything great by now, it works as it's supposed to, every modification gets commited to the DB. But my problem is the following - when i get data from more than one table. like this :
string myCmd =
"select r.id, u.username, r.creation_date, r.owner
from report r inner join users u on r.user_id == u.id";
I know I could write the DataAdapter
's update command manually (DataAdapter.UpdateCommand
) , before saving, but i'm not sure how. Can you give me some directions?
Thanks!
Upvotes: 3
Views: 16414
Reputation: 1176
Check out the example provided in MSDN. I guess OracleDataAdapter works with same logic. http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx
Here is the update command generation section from specified link
// Create the UpdateCommand.
command = new SqlCommand("UPDATE Customers SET CustomerID = @CustomerID, "+
"CompanyName = @CompanyName WHERE CustomerID = @oldCustomerID", connection);
// Add the parameters for the UpdateCommand.
command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");
SqlParameter parameter = command.Parameters.Add("@oldCustomerID",
SqlDbType.NChar, 5, "CustomerID");
parameter.SourceVersion = DataRowVersion.Original;
adapter.UpdateCommand = command;
Upvotes: 4