SQL problem - simple?

Reply

Join Date: Apr 2009
Posts: 30
Reputation: kn2790 is an unknown quantity at this point 
Solved Threads: 0
kn2790 kn2790 is offline Offline
Light Poster

SQL problem - simple?

 
0
  #1
May 1st, 2009
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 & "')"
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: Zermoth is an unknown quantity at this point 
Solved Threads: 0
Zermoth's Avatar
Zermoth Zermoth is offline Offline
Newbie Poster

Re: SQL problem - simple?

 
0
  #2
May 1st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 30
Reputation: kn2790 is an unknown quantity at this point 
Solved Threads: 0
kn2790 kn2790 is offline Offline
Light Poster

Re: SQL problem - simple?

 
0
  #3
May 1st, 2009
lol no they are the correct names of the textboxes, any other ideas?
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,093
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 125
debasisdas's Avatar
debasisdas debasisdas is online now Online
Postaholic

Re: SQL problem - simple?

 
0
  #4
May 2nd, 2009
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.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: SQL problem - simple?

 
0
  #5
May 7th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC