954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SQL problem - simple?

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 & "')"
kn2790
Light Poster
30 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
& "'" & 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

Zermoth
Newbie Poster
8 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

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

kn2790
Light Poster
30 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

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.

debasisdas
Posting Genius
6,870 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You