so im trying 2 add data to my table in the database, done all the connection (OLEDB one)

so this code adds to my database:

SQL = "Insert into Bookings(StaffID) values('" & stafid.Text & "')"
        DC1 = New OleDbCommand(SQL, cN)
        DC1.ExecuteNonQuery()
        MsgBox("Record Saved, Thank you!", MsgBoxStyle.OkOnly, "")

this is one column, im trying to add more to the table StaffID

whats wrong with this SQL statement to add all the fields to the database?

SQL = "Insert into Bookings(StaffID,RoomID,Date required,Time required,Additional requirements) values('" _
            & "'" & stafid.Text & "', " _
            & "'" & rooid.Text & "', " _
            & "'" & date1.Text & "', " _
            & "'" & time1.Text & "', " _
            & "'" & areq.Text & "')"

Recommended Answers

All 4 Replies

& "'" & stafid.Text & "', " _
            & "'" & rooid.Text & "', " _
            & "'" & date1.Text & "', " _
            & "'" & time1.Text & "', " _
            & "'" & areq.Text & "')"

rename rooid.Text to roomid.Text

also

stafid.Text to staffid.Text

if thats not the correct names

lol no they are the correct names of the textboxes, any other ideas?

what exactly is the error message .

print the SQL string or display in A message box before executing the same. SO that yo can check if the SQL is being framed properly or not.

Hi,

Field Names which have SpecialCharacters/Spaces, need to be enclosed in a Square Bracket..
Try This :

SQL = "Insert into Bookings(StaffID,RoomID,[Date required]," _
& " [Time required],[Additional requirements]) values('" _
& "'" & stafid.Text & "', " _
& "'" & rooid.Text & "', " _
& " #" & date1.Text & "#, " _
& " #" & time1.Text & "#, " _
& "'" & areq.Text & "')"

Also, Date/Time Fields need to to be wrapped in with #, instead of single quote.

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.