我做了一个在表中添加记录的函数:
Public Function AjouterCleint _
(ByVal pcode As String, ByVal prsoc As String, ByVal padresse As String, ByVal pcp As String) As Boolean
On Error GoTo ErrorHandler
MsgBox " code " & " : " & pcode & " / rsoc : " & prsoc & " / adresse : " & padresse & " / cp : " & pcp
AjouterCleint = False
Dim rs As New Recordset
Set rs = New Recordset
Dim conn As ADODB.Connection
Dim strIPAddress As String
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=LOCALHOST;" _
& " DATABASE=ste002;" _
& "UID=root;PWD=; OPTION=3"
con.Open
Set rs = Nothing
rs.CursorLocation = adUseClient
SQL = "INSERT INTO Client (code,rsoc,adresse,cp) VALUES ('" _
& pcode & "','" & prsoc & "','" & padresse & "','" & pcp & "')"
MsgBox "5"
rs.Open SQL, con, 3, 3
MsgBox "6"
Set rs = Nothing
MsgBox "7"
con.Close
MsgBox "8"
Set con = Nothing
MsgBox "9"
AjouterCleint = True
ErrorHandler:
MsgBox Err.Number & vbLf & Err.Description & vbLf & Err.HelpContext & vbLf & Err.Source, , ""
End Function
参数的值不是我使用的一些。(我进入消息框:
code: ????, rsoc: ????, adresse :???? , cp :1
当我以普通方式使用此功能时(我将其添加到模块中,并将其称为:
a = AjouterCleint("13234", "1234", "1234", "1234")
它可以工作,但是当我把它放在一个 dll 中时,出现了一个错误:
2147217900
[MySQL][ODBC 3.51 DRIVER] ... SYNTHAX error in “???????????????” in line 1.
1000440
Microsoft OLE DB providerfor ODBC drivers
例外是在这一行:
rs.Open SQL, con, 3, 3
我删除了 INSET COMMAND 中的所有参数并替换了
SQL = "INSERT INTO Client (code,rsoc,adresse,cp) VALUES ('" _
& pcode & "','" & prsoc & "','" & padresse & "','" & pcp & "')"
经过
SQL = "INSERT INTO Client (code,rsoc,adresse,cp) VALUES (12,12,12,12)"
它在 dll 中工作(我在其他项目中调用它并且它工作)。
但我必须使用参数。
所以,任何建议!
非常感谢。
PS:“recordset.addnew”也不起作用,并且也引发了错误。
这就是我在 dll 中调用函数的方式:
Private Declare Function FunctionCalled Lib "C:\dlls\vbm2dll\Called.dll" _
(ByVal strValuePassed As String) As String
Private Declare Function AjouterCleint Lib "C:\dlls\vbm2dll\Called.dll" _
(ByVal pcode As String, ByVal prsoc As String, ByVal padresse As String, ByVal pcp As String) As Boolean
Private Sub Form_load()
txbValuePassed = "abc"
End Sub
Private Sub cmdCall_Click()
txbValueReturned = FunctionCalled(txbValuePassed)
a = AjouterCleint("1104", "1", "1", "1")
MsgBox a & ""
End Sub