我使用DataAdapter和DataTable在Oracle表中使用ODP.NET提供程序编辑/添加数据。
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);之后,我修改数据表中的数据,将其绑定到网格并编辑它,并按如下方式保存:
OracleCommandBuilder _cmdBld = new OracleCommandBuilder(adptr);
adptr.Update(ds, "report");到现在为止,一切都很棒,它按预期的方式工作,每一次修改都会执行到DB中。但是,当我从多个表中获得数据时,我的问题是如下所示。就像这样:
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";我知道我可以在保存之前手动编写DataAdapter的update命令(DataAdapter.UpdateCommand),但是我不知道怎么写。你能告诉我一些方向吗?
谢谢!
发布于 2011-05-26 07:52:47
查看MSDN中提供的示例。我想OracleDataAdapter的工作逻辑是一样的。http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx
以下是来自指定链接的更新命令生成部分
// 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;https://stackoverflow.com/questions/6135215
复制相似问题