首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataAdapter更新命令

DataAdapter更新命令
EN

Stack Overflow用户
提问于 2011-05-26 07:38:10
回答 1查看 16K关注 0票数 3

我使用DataAdapterDataTable在Oracle表中使用ODP.NET提供程序编辑/添加数据。

代码语言:javascript
复制
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);

之后,我修改数据表中的数据,将其绑定到网格并编辑它,并按如下方式保存:

代码语言:javascript
复制
OracleCommandBuilder _cmdBld = new OracleCommandBuilder(adptr);
adptr.Update(ds, "report");

到现在为止,一切都很棒,它按预期的方式工作,每一次修改都会执行到DB中。但是,当我从多个表中获得数据时,我的问题是如下所示。就像这样:

代码语言:javascript
复制
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),但是我不知道怎么写。你能告诉我一些方向吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-26 07:52:47

查看MSDN中提供的示例。我想OracleDataAdapter的工作逻辑是一样的。http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx

以下是来自指定链接的更新命令生成部分

代码语言:javascript
复制
// 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;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6135215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档