Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am building vb.net-ms access database project.
In one of the "Insert" command, I am getting "Please check the number" exception pointing at ExecuteNonQuery code line.
I am new to programming. Here is my code:
XML
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click

        If cbMachine.SelectedIndex <> -1 And _
        cbShift.SelectedIndex <> -1 And _
        cbWdiv.SelectedIndex <> -1 And _
        cbChky.SelectedIndex <> -1 And _
        cbBukby.SelectedIndex <> -1 And _
        cbRemarks.SelectedIndex <> -1 Then
            cmdInsert.CommandText = "INSERT INTO buktab ([Booking Date],[Machine Type],[Shift],[MS Division / Ward], Chowky, [Booked By], [Site Address], [Remarks]) VALUES(" &
                DateTimePicker1.Value.Date & ", '" & cbMachine.Text & "', '" & cbShift.Text & "', '" & cbWdiv.Text & "', '" & cbChky.Text & "', '" & cbBukby.Text & "', '" & cbSite.Text & "', '" & cbRemarks.Text & "');"

            cmdInsert.CommandType = CommandType.Text
            cmdInsert.Connection = cnnOLEDB
            cmdInsert.ExecuteNonQuery()

            MsgBox("Machine Booked Successfully!")
            'Resetting all comboboxes
            DateTimePicker1.Text = Today()
            cbMachine.SelectedIndex = -1
            cbShift.SelectedIndex = -1
            cbWdiv.SelectedIndex = -1
            cbChky.SelectedIndex = -1
            cbBukby.SelectedIndex = -1
            cbSite.Text = "Please Type Manually"
            cbRemarks.SelectedIndex = -1
        Else
            MsgBox(" Please Enter the Missing Values")
        End If
        cmdInsert.Dispose()
    End Sub


Please let me know, where I am going wrong. Any help in this regard is highly appreciated.
Thanks in advance.
Posted
Comments
Dave Kreskowiak 13-Nov-13 10:59am    
You're not getting an exception that says "Please check the number". It's something else. Copy and paste the EXACT exception message into your post.
Member 10318953 13-Nov-13 11:15am    
It says,
" OleDbException was unhandled
Please Check the Number
Troubleshooting Tips:
Get general help for this exception.
Search for more help online..
Exception Settings:
Actions: _ _ _ _ _ _ _ _ _"
Dave Kreskowiak 13-Nov-13 15:56pm    
OK, you still haven't supplied the exact error message. "OleDbException" is the exception type, not the message contained within it. There is no such message in the standard errors you can get back that start with "Please check the number".

1 solution

Do NOT use string concatenation to build an SQL query like that. Google for "SQL Injection Attack" to find out why what you're doing is so bad.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900