为了账号安全,请及时绑定邮箱和手机立即绑定

为什么提示vb 实时错误‘91’对象变量或 With 块变量没有设置?

为什么提示vb 实时错误‘91’对象变量或 With 块变量没有设置?

忽然笑 2023-04-20 19:15:10
Public Function viewData(ByVal txtSQL As String, dataGridAll As DataGrid) As IntegerDim rstData As ADODB.RecordsetDim result As String'检索需要的信息result = ExecuteSQL(txtSQL, rstData, False)'设置datagrid的数据源If rstData.RecordCount <> 0 ThenSet dataGridAll.DataSource = rstDataviewData = rstData.RecordCountElseMsgBox "还没有数据!", vbOKOnly + vbExclamation, "警告"viewData = 0End IfEnd Function数据库采用sql2000'函数名:ExecuteSQL'说 明:执行SQL语句'参 数:SQL As String, rst As ADODB.Recordset, Optional enableWrite As Boolean'返回值:SQL语句执行成功——true,失败——false' ******************************************************************************Public Function ExecuteSQL(ByVal SQL As String, rst As ADODB.Recordset, _Optional enableWrite As Boolean = True) As BooleanDim con As New ADODB.ConnectionDim sTokens() As StringOn Error GoTo Execute_ErrorsTokens = Split(SQL)Set con = New ADODB.Connectioncon.Open ConnectStringSet rst = New ADODB.RecordsetIf enableWrite Thenrst.Open Trim$(SQL), con, adOpenStatic, adLockOptimisticElserst.Open Trim$(SQL), con, adOpenStatic, adLockReadOnlyEnd IfExecuteSQL = TrueExit FunctionExecute_Error:ExecuteSQL = FalseExit FunctionEnd Function
查看完整描述

1 回答

?
四季花海

TA贡献1811条经验 获得超5个赞

ExecuteSQL 这个函数贴出来,估计是数据库没链接上

Public Function viewData(ByVal txtSQL As String, dataGridAll As DataGrid) As Integer 
Dim rstData As ADODB.Recordset 
Dim result As String 
'检索需要的信息 
result = ExecuteSQL(txtSQL, rstData, False) 
if result=true then
'设置datagrid的数据源 
If rstData.RecordCount <> 0 Then 
Set dataGridAll.DataSource = rstData 
viewData = rstData.RecordCount 
Else 
MsgBox "还没有数据!", vbOKOnly + vbExclamation, "警告" 
viewData = 0 
End If 
else
msgbox "数据库链接失败"
end if
End Function

查看完整回答
反对 回复 2023-04-23
  • 1 回答
  • 0 关注
  • 230 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信