943,929 Members | Top Members by Rank

Ad:
May 1st, 2009
0

SQL problem - simple?

Expand Post »
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. SQL = "Insert into Bookings(StaffID) values('" & stafid.Text & "')"
  2. DC1 = New OleDbCommand(SQL, cN)
  3. DC1.ExecuteNonQuery()
  4. 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?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. SQL = "Insert into Bookings(StaffID,RoomID,Date required,Time required,Additional requirements) values('" _
  2. & "'" & stafid.Text & "', " _
  3. & "'" & rooid.Text & "', " _
  4. & "'" & date1.Text & "', " _
  5. & "'" & time1.Text & "', " _
  6. & "'" & areq.Text & "')"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
kn2790 is offline Offline
30 posts
since Apr 2009
May 1st, 2009
0

Re: SQL problem - simple?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. & "'" & stafid.Text & "', " _
  2. & "'" & rooid.Text & "', " _
  3. & "'" & date1.Text & "', " _
  4. & "'" & time1.Text & "', " _
  5. & "'" & areq.Text & "')"

rename rooid.Text to roomid.Text

also

stafid.Text to staffid.Text

if thats not the correct names
Last edited by Zermoth; May 1st, 2009 at 11:16 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zermoth is offline Offline
8 posts
since Dec 2008
May 1st, 2009
0

Re: SQL problem - simple?

lol no they are the correct names of the textboxes, any other ideas?
Reputation Points: 10
Solved Threads: 0
Light Poster
kn2790 is offline Offline
30 posts
since Apr 2009
May 2nd, 2009
0

Re: SQL problem - simple?

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.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
May 7th, 2009
0

Re: SQL problem - simple?

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
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Denying Access Database
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: need help with VB6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC