在做一个系统时以下代码错误吗???是怎么回事啊??时间紧迫啊!!!
Public Function executesql(ByVal sql As String, msgstring As String) As adodb.RecordsetDim cnn As adodb.connection
dimrst As adodb.Recordset
Dim stokens() As String
On Error GoTo executesql_error
stokens = Split(sql)
Set cnn = New adodb.connection
cnn.open connectstring
If InStr("insert,delete,update", UCase$(stokens(0))) Then
cnn.execute sql
msgstring = stokens(0) & "query successful"
Else
Set rst = New adodb.Recordset
rst.open (sql), cnn, adopendeyset, adlockoptimistic
Set executesql = rst
msgstring = "查询到" & rst.recordcount & "条记录"
End If
executesql_exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
executesql_error:
msgstring = "查询错误:" & Err.Description
Resume executesql_exit
End Function
Public Function connectstring() As String
connectstring = "provider=sqloledb;uid=sa;pwd=sayu;database=xsgl"
End Function
Sub main()
Dim flogin As New frmlogin
flogin.Show vbModal
If Not flogin.ok Then
End
End If
Unload flogin
Set fmainform = New frmain
fmainform.Show
End Sub
Public Function testtxt(txt As String) As Boolean
If Trim(txt) = "" Then
testtxt = False
Else
testtxt = True
End If
End Function --------------------编程问答-------------------- 提示什么错误啊? --------------------编程问答-------------------- 代码放标准模块,对工程的启动设置为:
Sub main()
Sub main()中的代码作了修改,
--------------------编程问答-------------------- if InStr( "insert,delete,update ", UCase$(stokens(0))) then
Option Explicit
Public Function executesql(ByVal sql As String, msgstring As String) As adodb.Recordset
Dim cnn As adodb.Connection
dimrst As adodb.Recordset
Dim stokens() As String
On Error GoTo executesql_error
stokens = Split(sql)
Set cnn = New adodb.Connection
cnn.Open connectstring
If InStr("insert,delete,update ", UCase$(stokens(0))) Then
cnn.Execute sql
msgstring = stokens(0) & "query successful "
Else
Set rst = New adodb.Recordset
rst.Open (sql), cnn, adopendeyset, adLockOptimistic
Set executesql = rst
msgstring = "查询到 " & rst.RecordCount & "条记录 "
End If
executesql_exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
executesql_error:
msgstring = "查询错误: " & Err.Description
Resume executesql_exit
End Function
Public Function connectstring() As String
connectstring = "provider=sqloledb;uid=sa;pwd=sayu;database=xsgl "
End Function
Sub main()
fLogin.Show vbModal
If Not fLogin.OK Then
fmainform.Show
Unload fLogin
End If
End Sub
Public Function testtxt(txt As String) As Boolean
If Trim(txt) = " " Then
testtxt = False
Else
testtxt = True
End If
End Function
这里需要修改一下
因为instr返回的是integer类型的,不是boolean型。
看一下这个函数:
Public Function testtxt(txt As String) As Boolean
If Trim(txt) = " " Then
testtxt = False
Else
testtxt = True
End If
End Function
Trim(txt) = " " 这个永远都是false。
--------------------编程问答-------------------- 谢谢各位了.
好像还不行,提示的错误是:第一句 Public Function executesql(ByVal sql As String, msgstring As String) As adodb.Recordset
用户定义类型未定义!
补充:VB , 数据库(包含打印,安装,报表)