【第一次机房】查询学生余额遇到的问题(错误代码13,数据不匹配)

在敲机房第一个窗体的时候,遇到了一个很折磨人的问题,

数据类型不匹配,直接不知道怎么入手解决问题,确认过数据库里的数据和数据类型都是正确的,然后确认了数据库的连接语句也确认无误。

最后发现是在数据定义的时候出现了错误。

第一次敲的时候,没有在ADODB.Record后面加上“set”。“Dim mrc As ADODB.Recordset”是对数据集进行定义,数据库中的所有的表都需要通过它打开和操作。

Option Explicit

Private Sub cmdExit_Click()
    If MsgBox("是否退出程序?", vbOKCancel, "请选择") = vbOK Then
        Unload Me
    End If
End Sub

Private Sub cmdInquire_Click()
    Dim txtSQL As String
    Dim MsgText As String
    Dim mrc As ADODB.Recordset

    If Trim(txtCardID.Text) = "" Then
        MsgBox "卡号不能为空!"
        txtCardID.SetFocus
        Exit Sub
    Else
    txtSQL = "select * from student_Info where cardno='" & Trim(txtCardID.Text) & "'"
    Set mrc = ExecuteSQL(txtSQL, MsgText)  '执行查询语句
        If mrc.EOF = True Then
            MsgBox "该卡没有注册,请重新输入!"
            txtCardID.Text = ""
            txtCardID.SetFocus
        Else
'将信息填入对应位置
            txtStudentNo.Text = Trim(mrc.Fields(1))
            txtStudentName.Text = Trim(mrc.Fields(2))
            txtSex.Text = Trim(mrc.Fields(3))
            txtDepartment.Text = Trim(mrc.Fields(4))
            txtGrade.Text = Trim(mrc.Fields(5))
            txtClass.Text = Trim(mrc.Fields(6))
            txtState.Text = Trim(mrc.Fields(10))
            txtExplain.Text = Trim(mrc.Fields(8))
            txtCash.Text = Trim(mrc.Fields(7))
        End If
    End If
End Sub


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章