2014-10-01 45 views
0

我認爲缺少某些東西或者我使用了錯誤的語法。你能幫我追蹤我的錯誤嗎?查詢值和目標字段的數量不一樣

私人小組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 

末次

請幫助。我是一個新手:(

回答

1

您的VALUES字符串或多或少逗號分隔的項目以外還有的tblScholarProfile表中的字段。

  • 看那解析SQL字符串,並確保每個值與現場相匹配在表
  • 如果有一個標識列,確保你沒有把它放置在VALUES列表
  • 確保您不會錯過任何'字符串分隔符

此外,在文本框一個'將導致一個錯誤,是一個SQL注入漏洞,最起碼你應該replace()在提交的文本中的任何'字符''(2×')逃避它們。

0

您錯過了一個較高的逗號txtSchoolID + ",'" + txtSSName檢查值,您會發現

相關問題