如何在对象命令的 CommandText 中加入 DML 语句

发布于 2024-07-09 01:01:59 字数 615 浏览 7 评论 0原文

为了从 SQL Server 数据库获取数据,我可以使用下面的代码,

Dim sql As String = "SELECT emp_id, emp_name FROM emp; SELECT dep_id, dep_name FROM department;"
Dim da As New SqlClient.SqlDataAdapter(sql, connString)
Dim ds As New DataSet("Data")

da.Fill(ds)

我将在 ds 数据集中获得两个表。 如何为 Oracle 数据库编写相同的代码? 我尝试按照上面的方式编码,但收到错误消息。 ORA-00911:无效字符

此外,我还想使用 DELETE 语句。 例如

Dim sql As String = "DELETE FROM emp WHERE emp_id = 1; DELETE FROM department WHERE dep_id = 4"
Dim cmd As New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()

谢谢。

For taking data from SQL Server database, I can use the code as below

Dim sql As String = "SELECT emp_id, emp_name FROM emp; SELECT dep_id, dep_name FROM department;"
Dim da As New SqlClient.SqlDataAdapter(sql, connString)
Dim ds As New DataSet("Data")

da.Fill(ds)

I will get two tables in ds dataset. How can I code the same for Oracle database? I try to code as the above, but I got the error msg. ORA-00911: Invalid character

Moreover, I'd like to use the DELETE statement also. For e.g.

Dim sql As String = "DELETE FROM emp WHERE emp_id = 1; DELETE FROM department WHERE dep_id = 4"
Dim cmd As New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你到最终 2024-07-16 01:01:59

为了通过 Command 对象执行多个 DML 语句,这些语句必须放在 BEGIN ... END 块中。 例如

Dim sql As String = "BEGIN DELETE FROM emp WHERE emp_id = 1; DELETE FROM department WHERE dep_id = 4; End;"
...

In order to execute multiple DML statements by a Command object, the statements must be put in a block BEGIN ... END. For e.g.

Dim sql As String = "BEGIN DELETE FROM emp WHERE emp_id = 1; DELETE FROM department WHERE dep_id = 4; End;"
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文