VB程序调试失败求人帮忙~

来源:百度知道 编辑:UC知道 时间:2024/06/15 20:26:40
程序是这样的。运行会说“未找到方法或数据成员”错误在“.Open”
如果改成Dim myConstr As Adodc,提示就变成“无效限定符”错误在“myConstr”(.OPEN前面那个)
Private Sub Form_Load()
Dim myConstr As Adodc
myConstr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= \db1.mdb"
myConstr.Open myConstr
End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()
Dim myrs As New ADODB.Recordset
myrs.Open "select count(*) from StuInfo where user='" & Trim(TxtStuCode.Text) & "'", mConStr, adOpenStatic, adLockReadOnly
If myrs(0) = 0 Then
myrs.Close
MsgBox "输入的账号不存在", vbOKOnly, "提示"
TxtStuCode.SetFocus
Exit Sub
End If
If myrs(0) > 1 Then
MsgBox "账号错误", vbOKOnly, "提示"
TxtStuCode.SetFocus
End If
myrs.Close
myrs.Open "select count(*) from StuInfo where user='" & Trim(TxtStuCode.Text) & &

Private Sub Form_Load()
Dim myConstr As Adodc
myConstr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= \db1.mdb"
myConstr.Open myConstr
End Sub

****************************
这里写的也太不着调了吧? myConstr 到底是什么类型啊?
如果是adodc,你怎么能给他赋字符串?更离谱的是下面用了open的方法.
然后下面的myrs 的open里面用的居然是 mConstr.
不过我还是看明白了你的意思,你这样改:
1.Public mConstr as new adodb.connection '写在通用里面
2.Private Sub Form_Load()
mConstr.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= \db1.mdb"
mConstr.open
End Sub 'Form_Load改成这样就可以了

不过你下面的一些代码还是有些Bug,你自己好好调试调试

Dim myConstr As string
这样就对了。