罗马假日在线观看英语:VB中遇到实时错误91

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 19:13:26
Option Explicit
Const allinfo_in = "select * from Productin where "
Const allinfo_out = "select * from Productout"
Private Sub Command1_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc1 As ADODB.Recordset
Dim s As String

If Option1.Value = True Then
If Text1.Text = "" Then
If Text3.Text = "" Then
s = "Pname='" + CStr(Text2.Text) + "';"
Else
s = "Pname='" + CStr(Text2.Text) + "' and Pdate='" + CStr(Text3.Text) + "';"
End If
Else
If Text3.Text = "" Then
s = "Pnumber='" + CStr(Text1.Text) + "' and Pname='" + CStr(Text2.Text) + "';"
Else
s = "Pnumber ='" + CStr(Text1.Text) + "' and Pname='" + CStr(Text2.Text) + "' and Pdate = '" + CStr(Text3.Text) + "';"
End If
End If

s = allinfo_in + s
txtSQL = s
Set mrc1 = New ADODB.Recordset
Set mrc1 = Module1.ExecuteSQL(txtSQL, MsgText)

With MSFlexGrid1
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "Pnumber"
.TextMatrix(1, 1) = "Pname"
.TextMatrix(1, 2) = "Pdate"
.TextMatrix(1, 3) = "Pamount"
Do While mrc1.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc1.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc1.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc1.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc1.Fields(3)
mrc1.MoveNext

Loop
End With
mrc1.Close
End If
End Sub
这是我在做一个数据库的时候遇到的一个问题,当运行到With MSFlexGrid1的时候就会出现错误91,我用一个MSGBOX 测试的时候是可以的,但是在执行的时候就是不行,好像是与数据库的连接有关,哪位高手能不能指点一下,怎么来检查是不是与数据库连接完整了?谢谢