vbs中oracle数据库接续失败

vbs中oracle数据库接续失败,第1张

数据库的字符串是否写错了或者重新配置一下数据库服务名OraID。

先用VB自带的那个直接工具先连上,再把连接地址复制出来,修改一下。

参考格式:Provider=OraOLEDB.Oracle.1Password=密码PersistSecurityInfo=TrueUserID=用户名DataSource=数据库网络服务名。

1. Open a new project in Visual Basic and add a Reference to the Microsoft ActiveX Data Objects library.

2. Place the following controls on the form:

Control Name Text/Caption

Button cmdCheckCheck

Button cmdSend Send

Text BoxtxtInput

Label lblInputInput:

3.

From the Tools menu, choose Options, Click the "Default Full Module

View" option, and then click OK. This allows you to view all of the code

for this project.

4. Paste the following code into your code window:

Option Explicit

Dim Cn As ADODB.Connection

Dim CPw1 As ADODB.Command

Dim CPw2 As ADODB.Command

Dim Rs As ADODB.Recordset

Dim Conn As String

Dim QSQL As String

Private Sub cmdCheck_Click()

CPw1(0) = Val(txtInput.Text)

Set Rs = CPw1.Execute

MsgBox "Item_Number = " &Rs(0) &". Depot_Number = " &Rs(1) &"."

Rs.Close

End Sub

Private Sub cmdSend_Click()

CPw2(0) = Val(txtInput.Text)

CPw2.Execute

MsgBox "Return value from stored procedure is " &CPw2(1) &"."

End Sub

Private Sub Form_Load()

'You will need to replace the "*" with the appropriate values.

Conn = "UID=*****PWD=****DRIVER={Microsoft ODBC for Oracle}" _

&"SERVER=*****"

Set Cn = New ADODB.Connection

With Cn

.ConnectionString = Conn

.CursorLocation = adUseClient

.Open

End With

QSQL = "Select Item_Number, Depot_Number From adooracle Where " _

&"item_number = "

Set CPw1 = New ADODB.Command

With CPw1

.ActiveConnection = Cn

.CommandText = QSQL

.CommandType = adCmdText

.Parameters.Append .CreateParameter(, adInteger, adParamInput)

End With

QSQL = "adoinsert"

Set CPw2 = New ADODB.Command

With CPw2

.ActiveConnection = Cn

.CommandText = QSQL

.CommandType = adCmdStoredProc

.Parameters.Append .CreateParameter(, adInteger, adParamInput)

.Parameters.Append .CreateParameter(, adDouble, adParamOutput)

End With

End Sub

Private Sub Form_Unload(Cancel As Integer)

Cn.Close

Set Cn = Nothing

Set CPw1 = Nothing

Set CPw2 = Nothing

End Sub


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存