如何执行在C#中使用Oracle ODP.Net一个update语句 [英] How to execute a update statement using Oracle ODP.Net in C#

查看:431
本文介绍了如何执行在C#中使用Oracle ODP.Net一个update语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Oracle.DataAccess.Client 甲骨文在我的 ASP.Net 应用程序数据库工作。有一个在 MSDN 对于 ODP.Net 的Oracle 的文档真的非常糟糕:(。我无法找到答案没有帮助文档这个简单的问题。

I am using Oracle.DataAccess.Client to work with Oracle database in my ASP.Net application. There is no help documentation in MSDN for ODP.Net and Oracle's documentation really really bad :(. I am not able find answer to this simple question.

是没可能,而无需建立一个对象和更新数据集执行一个简单的更新语句

Is it not possible to execute a simple update statement without having to build a dataset object and updating the dataset?

如何使用执行更新语句的甲骨文ODP.Net C#

How to execute a update statement using Oracle ODP.Net in C#?

推荐答案

我将需要检查的确切语法,但这里是一些快速code把我的头顶部

I will need to check the exact syntax, but here is some quick code off the top of my head

using (OracleConnection con = new OracleConnection(...))
{
  con.Open();
  OracleCommand cmd = con.CreateCommand();
  cmd.CommandType = CommandType.Text;
  cmd.CommandText = "update table set col1 = :param1, col2 = :param2 where key = :keyValue";
  cmd.Parameters.AddWithValue("param1", 1);
  cmd.Parameters.AddWithValue("param2", "Text data");
  cmd.Parameters.AddWithValue("keyValue", "1");
  cmd.ExecuteNonQuery();
}

上面创建一个命令对象设置的命令,执行SQL Update语句,在这个例子中,我展示的一种方式设置一个参数化查询,你应该总是与参数化查询去。一旦命令设置你刚才叫的ExecuteNonQuery 来实际执行命令。

The above creates a command object sets the command up to execute an SQL Update statement, in this example I show one way to setup a parameterized query, you should always go with a parameterized query. Once the command is setup you just call ExecuteNonQuery to actually execute the command.

这篇关于如何执行在C#中使用Oracle ODP.Net一个update语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆