请各位大侠给出用VB.NET连接oracle数据库并执行sql查询语句的代码示例,谢谢!!

请各位大侠给出用VB.NET连接oracle数据库并执行sql查询语句的代码示例,谢谢!!,第1张

Dim OraSession As Object '会话对象

Dim OraDatabase As Object '数据库对象

Dim OraDynaset As Object'动态集对象

Dim OraDatabase As Object’字段集对象

Set OraSession =CreateObject("OracleInProcServer.XOraSession")

Set OraDatabase=OraSession.CreateDatabase

("Demo","scott/tiger",0&)'建立数据库连接

Set OraDynaset=OraDatabase.CreateDynaset("select*from

student",0&)'初始化动态集对象

’添加记录

'Begin an AddNew

OraDynaset.DbAddNew

OraDynaset.Fields("ID").value="1000"

’ID为列名

OraDynaset.DbUpdate'更新数据到表

’删除

OraDynaset.DbDelete

'修改

OraDynaset.DbEdit

OraDynaset.Fields("ID").value="101210"

OraDynaset.DbUpdate

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim shkcode1 As String

Dim shimei1 As String

Dim inymd1 As String

Dim sqlstr As String

' Dim dr As DataRow

shkcode1 = DataGridView1.Rows(4).Cells(0).Value

shimei1 = DataGridView1.Rows(4).Cells(1).Value

inymd1 = DataGridView1.Rows(4).Cells(2).Value

sqlstr = " insert into EA_M1施设职员(shkcode,shimei,inymd) values ('" &shkcode1 &"','" &shimei1 &"','" &inymd1 &"')"

Dim connection As New OracleConnection("连接字符串")

Dim cmd As New OracleCommand(sqlstr, connection)

Try

connection.Open()

Dim rows As Integer = cmd.ExecuteNonQuery()

if rows >0 then

'说明执行成功了.可以做之后的 *** 作

end if

Catch E As System.Data.OracleClient.OracleException

connection.Close()

Throw New Exception(E.Message)

End Try

end sub

ps:建议去学学ADO.Net 不难的.

写个存储过程

然后 循环

select a ,b into v_a ,v_b from table_name

update table_name set a =v_b ,b= v_a

commit


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6627292.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-25
下一篇 2023-03-25

发表评论

登录后才能评论

评论列表(0条)

保存