查询值和目标字段的数量不相同

时间:2014-10-01 09:42:40

标签: vb6

我认为缺少某些东西或者我使用了错误的语法。你能帮我跟踪一下我的错误吗?

Private Sub AddScholarbtn_Click()

If txtSchoolID = "" Then
    MsgBox ("Input ID")
ElseIf txtSSName = "" Then
    MsgBox ("Input Surname")
ElseIf txtSGName = "" Then
    MsgBox ("Input Given Name")
ElseIf txtSMName = "" Then
    MsgBox ("Input Middle Name")
ElseIf txtAddress = "" Then
    MsgBox "Null"
ElseIf txtBirthPlace = "" Then
    MsgBox "Null"
ElseIf ComboMonth = "" Then
    MsgBox "Select Month"
ElseIf ComboDay = "" Then
    MsgBox ("Select Day")
ElseIf ComboYear = "" Then
    MsgBox "Select Year"
ElseIf comboGender = "" Then
    MsgBox "Select Gender"
ElseIf ComboCivilStatus = "" Then
    MsgBox "Select Status"
ElseIf txtAge = "" Then
    MsgBox ("Input Age")
ElseIf txtContactInfo = "" Then
    MsgBox "Null"
ElseIf txtEmail = "" Then
    MsgBox "Null"
ElseIf txtGuardian = "" Then
    MsgBox "Null"
ElseIf txtGContact = "" Then
    MsgBox ("Null")
ElseIf txtYOA = "" Then
    MsgBox "Null"
ElseIf comboProgram = "" Then
    MsgBox "Null"

Else

    Dim ans
    ans = MsgBox("Are you sure you want to Save this Scholar?", vbYesNo, "Save")
    If ans = vbYes Then


          ''''''''''''In this line where the yellow color/error occurs


    DBConnect.Execute "INSERT INTO tblScholarProfile VALUES(" + txtSchoolID + ",'" + txtSSName + "','" + txtSGName + "','" + txtSMName + "' ," & _
                    " '" + txtAddress + "','" + txtBirthPlace + "','" + ComboMonth + "'," + ComboDay + "," + ComboYear + "," & _
                    " '" + comboGender + "','" + ComboCivilStatus + "'," + txtAge + "," + txtContactInfo + ",'" + txtEmail + "','" + txtGuardian + "'," + txtGContact + "," + txtYOA + ",'" + comboProgram + "')"

我真的不知道我错了。

        MsgBox "You have successfully save a new Scholar"
    Else
        MsgBox "Save unsuccesful!"
    End If
    Unload Me
    MainMenuForm.Show

End If

End Sub

请帮忙。我是新手:(

2 个答案:

答案 0 :(得分:1)

VALUES字符串中的逗号分隔项目多于或少于tblScholarProfile表格中的字段。

  • 查看已解析的SQL字符串,并确保每个值与表中的字段匹配
  • 如果有标识列,请确保未将其包含在VALUES列表
  • 确保您没有遗漏任何'字符串分隔符

此外,其中一个文本框中的'会导致错误并且是一个SQL注入漏洞,至少应该{1}}提交的文本中包含replace()个字符' ''(2 x ')逃脱它们。

答案 1 :(得分:0)

您错过了一个较高的逗号txtSchoolID + ",'" + txtSSName检查了值,您会找到