Save Data in Database , Syntax error

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 32
Reputation: DATABASE is an unknown quantity at this point 
Solved Threads: 0
DATABASE DATABASE is offline Offline
Light Poster

Save Data in Database , Syntax error

 
0
  #1
Jun 1st, 2008
this the the code for inserting data in a database

  1. Dim cn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("database.mdb"))
  2. cn.Open()
  3. Dim cmdr As New Data.OleDb.OleDbCommand
  4. cmdr.CommandText = "SELECT [Customer_ID] FROM [Customers] WHERE FirstName LIKE '" & User.Identity.Name & "'"
  5. Dim id As Integer
  6. cmdr.Connection = cn
  7.  
  8. id = System.Convert.ToInt32(cmdr.ExecuteScalar())
  9. Dim cmd As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand
  10. Dim SQLTxt As String = "INSERT INTO Orders (Customer_ID,Total_price,Delivery,Ordered time)VALUES( '" & id & "','" & lblTotal.Text & "','" & CheckBox1.Checked & "','" & DateTime.Now() & "')"
  11.  
  12.  
  13.  
  14. cmd.Connection = cn
  15. cmd.CommandText = SQLTxt
  16. cmd.ExecuteNonQuery()
  17. cmd.Connection.Close()



the error
Syntax error in INSERT INTO statement.


Line 106: cmd.Connection = cn
Line 107: cmd.CommandText = SQLTxt
Line 108: cmd.ExecuteNonQuery()
Line 109: cmd.Connection.Close()


Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Save Data in Database , Syntax error

 
0
  #2
Jun 1st, 2008
I think you need Ordered Time in Brackets like this [Ordered Time]

If this solves the issue, please mark this thead as solved and give me some reputation points. Thanks!
--
"Dummy."
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 32
Reputation: DATABASE is an unknown quantity at this point 
Solved Threads: 0
DATABASE DATABASE is offline Offline
Light Poster

Re: Save Data in Database , Syntax error

 
0
  #3
Jun 1st, 2008
Originally Posted by ericstenson View Post
I think you need Ordered Time in Brackets like this [Ordered Time]

If this solves the issue, please mark this thead as solved and give me some reputation points. Thanks!

same problem
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Save Data in Database , Syntax error

 
0
  #4
Jun 1st, 2008
Ok, 2 questions...

First, is the error happening @ the insert or @ the select statement?

Second, when it crashes, can you paste what the value of SQLTxt is... like click on it and it should show you... Thanks.
--
"Dummy."
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