User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 430,001 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,505 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 400 | Replies: 3
Reply
Join Date: May 2006
Posts: 32
Reputation: DATABASE is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
DATABASE DATABASE is offline Offline
Light Poster

Save Data in Database , Syntax error

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

Dim cn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("database.mdb"))
        cn.Open()
        Dim cmdr As New Data.OleDb.OleDbCommand
        cmdr.CommandText = "SELECT [Customer_ID] FROM [Customers] WHERE FirstName LIKE '" & User.Identity.Name & "'"
        Dim id As Integer
        cmdr.Connection = cn
        
        id = System.Convert.ToInt32(cmdr.ExecuteScalar())
        Dim cmd As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand
        Dim SQLTxt As String = "INSERT INTO Orders (Customer_ID,Total_price,Delivery,Ordered time)VALUES( '" & id & "','" & lblTotal.Text & "','" & CheckBox1.Checked & "','" & DateTime.Now() & "')"
       
        

        cmd.Connection = cn
        cmd.CommandText = SQLTxt
        cmd.ExecuteNonQuery()
        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()


AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Posts: 287
Reputation: ericstenson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Save Data in Database , Syntax error

  #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  
Join Date: May 2006
Posts: 32
Reputation: DATABASE is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
DATABASE DATABASE is offline Offline
Light Poster

Re: Save Data in Database , Syntax error

  #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  
Join Date: Dec 2007
Posts: 287
Reputation: ericstenson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Save Data in Database , Syntax error

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 12:58 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC