Reply

Join Date: Dec 2005
Posts: 7
Reputation: cindynicole is an unknown quantity at this point 
Solved Threads: 0
cindynicole cindynicole is offline Offline
Newbie Poster

sql statement

 
0
  #1
Dec 14th, 2005
Hi all, I need a fresh set of eyes :eek: . Can anyone see what is wrong w/the sql statement?

Dim sql As String = "INSERT INTO order " & "VALUES ('" & itemId & "', '" & description & "', " & oNum & ")"

Danka, Cindy
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 134
Reputation: Yomet is an unknown quantity at this point 
Solved Threads: 10
Yomet Yomet is offline Offline
Junior Poster

Re: sql statement

 
0
  #2
Dec 14th, 2005
Hi cindynicole,

At first glance I cannot see anything flagrantly wrong, however, I don't know the structure of the table.

If you are not using all the fields of the table you have to specify which fields will hold the inserted data, i.e.
"INSERT INTO order (ID, Desc, oNum) " & _
"VALUES ('" & itemId & "', '" & description & "', " & oNum & ")"

Next, verify that your ID is unique, if necessary, and that it is of String type. Also verify that oNum is actually of numeric type.

Another thing is that if Description contains single quotes you will get an error since you are using single quotes as string delimiters, i.e. [, '" & description & "',]. The way around this is to use double quotes as delimiters, this makes the code look ugly but it works. Like so:
"VALUES ('" & itemId & "', " & Chr(34) & description & Chr(34) & ", " & oNum & ")"

That's all I can give you for now, if you still have problems I will need to know the table structure and anything else about the DB.

Hope this helps

Yomet
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 7
Reputation: cindynicole is an unknown quantity at this point 
Solved Threads: 0
cindynicole cindynicole is offline Offline
Newbie Poster

Re: sql statement

 
0
  #3
Dec 14th, 2005
Originally Posted by Yomet
Hi cindynicole,

At first glance I cannot see anything flagrantly wrong, however, I don't know the structure of the table.

If you are not using all the fields of the table you have to specify which fields will hold the inserted data, i.e.
"INSERT INTO order (ID, Desc, oNum) " & _
"VALUES ('" & itemId & "', '" & description & "', " & oNum & ")"

Next, verify that your ID is unique, if necessary, and that it is of String type. Also verify that oNum is actually of numeric type.

Another thing is that if Description contains single quotes you will get an error since you are using single quotes as string delimiters, i.e. [, '" & description & "',]. The way around this is to use double quotes as delimiters, this makes the code look ugly but it works. Like so:
"VALUES ('" & itemId & "', " & Chr(34) & description & Chr(34) & ", " & oNum & ")"

That's all I can give you for now, if you still have problems I will need to know the table structure and anything else about the DB.

Hope this helps

Yomet
Thank you Yomet,
Here is my function, trying out the code you suggested, I get a syntax error in my INSERT INTO

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Shared Function AddToOrderTbl(ByRef menuItems As ArrayList)
  2. 'received receipt array from order
  3. Dim adpOrder As New OleDbDataAdapter
  4. conn.Open()
  5. MsgBox("number in array is " & menuItems.Count & " oNum value should be count + 1")
  6.  
  7. 'loop thru array to get ind product ordered to add to order table
  8. For i As Integer = 0 To menuItems.Count - 1
  9. Dim newItem As Product
  10. newItem = menuItems.Item(i)
  11. Dim itemId As String = newItem.mId
  12. Dim description As String = newItem.mSize
  13. Dim oNum As Integer = menuItems.Count + 1
  14.  
  15.  
  16.  
  17. 'Dim sql As String = "INSERT INTO order " & "VALUES ('" & itemId & "', '" & description & "', " & oNum & ")"
  18.  
  19. Dim sql As String = "INSERT INTO order (productId, productDescription, orderNumber) " & "VALUES ('" & itemId & "', " & Chr(34) & description & Chr(34) & ", " & oNum & ")"
  20.  
  21.  
  22. 'view sql
  23. MsgBox(sql)
  24. Try
  25.  
  26. adpOrder.InsertCommand = New OleDbCommand(sql, conn)
  27.  
  28. adpOrder.InsertCommand.ExecuteNonQuery()
  29.  
  30. ''ListRecords() ' Invoke ListRecords method
  31. Catch ee As Exception
  32. MsgBox(ee.ToString)
  33. End Try
  34. Next
  35.  
  36.  
  37.  
  38. conn.Close()
  39.  
  40.  
  41. End Function

my table is order
fields are: productId as text
productDescription as text
orderNumber as number

and there is no PK

I print out the sql in a msg box and it's receiving the values intended and the sql looks right. but it won't INSERT

Again, Thank you for your time, if i can give you more info i will

Cindy
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 134
Reputation: Yomet is an unknown quantity at this point 
Solved Threads: 10
Yomet Yomet is offline Offline
Junior Poster

Re: sql statement

 
0
  #4
Dec 14th, 2005
Cindy,

The only things that I can see now are:
- Is your order.productId defined as Unique? If so you need to revise your table structure.
- Does your itemID contain single quotes (apostrophies)? If so use the Chr(34) for it as well.

From what I can see there is nothing else wrong with your SQL statement, however I am not used to working in .NET nor with ADODB so it might be something specific to these environments.

If it is specific to .NET you might wat to ask this question in the .NET forum.

Hope you succeed.

Yomet
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 7
Reputation: cindynicole is an unknown quantity at this point 
Solved Threads: 0
cindynicole cindynicole is offline Offline
Newbie Poster

Re: sql statement

 
0
  #5
Dec 14th, 2005
Yomet,
I will try the Chr(34) on my id as well.... there are no unuique fields, took them out thinking they would cause a problem.. thank you for your help, i'll let you know how it goes.
cindy
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 7
Reputation: cindynicole is an unknown quantity at this point 
Solved Threads: 0
cindynicole cindynicole is offline Offline
Newbie Poster

Re: sql statement

 
0
  #6
Dec 14th, 2005
Well, the Chr(34) didn't work. I'll keep looking and asking around. Thanks, Cindy
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