| | |
sql statement
![]() |
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
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
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
•
•
Join Date: Dec 2005
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
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
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)
Public Shared Function AddToOrderTbl(ByRef menuItems As ArrayList) 'received receipt array from order Dim adpOrder As New OleDbDataAdapter conn.Open() MsgBox("number in array is " & menuItems.Count & " oNum value should be count + 1") 'loop thru array to get ind product ordered to add to order table For i As Integer = 0 To menuItems.Count - 1 Dim newItem As Product newItem = menuItems.Item(i) Dim itemId As String = newItem.mId Dim description As String = newItem.mSize Dim oNum As Integer = menuItems.Count + 1 'Dim sql As String = "INSERT INTO order " & "VALUES ('" & itemId & "', '" & description & "', " & oNum & ")" Dim sql As String = "INSERT INTO order (productId, productDescription, orderNumber) " & "VALUES ('" & itemId & "', " & Chr(34) & description & Chr(34) & ", " & oNum & ")" 'view sql MsgBox(sql) Try adpOrder.InsertCommand = New OleDbCommand(sql, conn) adpOrder.InsertCommand.ExecuteNonQuery() ''ListRecords() ' Invoke ListRecords method Catch ee As Exception MsgBox(ee.ToString) End Try Next conn.Close() 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
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
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
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
![]() |
Similar Threads
- is there something wrong with my SQL statement? (PHP)
- Syntax error in "like" in sql statement (ASP.NET)
- Question about SQL statement (MS SQL)
- SQL statement error (ASP.NET)
- run sql statement in asp (ASP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: List of functions
- Next Thread: how VB get data from database randomly
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows





