如何在对象命令的 CommandText 中加入 DML 语句
为了从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了通过 Command 对象执行多个 DML 语句,这些语句必须放在 BEGIN ... 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.