Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Syntax error? 2

Status
Not open for further replies.

apex1x

IS-IT--Management
Joined
Aug 14, 2002
Messages
396
Location
US
Whenever I run this bit of code I get an INSERT INTO syntax error. It might be something really simple but I cant seem to see it at the moment. Any suggestions?

Code:
        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\working\sample.mdb;")
        cn.Open()
        For i = 0 To k - 1
            str = "INSERT INTO prtinvoice (Qty,Desc,Rate,Amount) VALUES('" & tempqty(i) & "','" & tempdesc(i) & "','" & temprate(i) & "','" & tempamount(i) & "')"
            cmd = New OleDbCommand(str, cn)
            cmd.ExecuteNonQuery()
        Next i
        cn.Close()
 
Perhaps you need to ad a space after the VALUES word
Code:
 VALUES ('"

Regards,
mansii
 
tried it... doesn't seem to have an effect. any other suggestions? :)
 
Well, I could think of 2 possibilities:

1. the [blue]Desc[/blue] field. Perhaps it's a keyword. Try renaming the fieldname.

2. Check these values
tempqty(i)
tempdesc(i)
temprate(i)
tempamount(i)
what are they anyway?

mansii
 
Haha, you were right on the money! Apparantly "desc" is the SQL command for descending... now it works like a charm :)
Thanks
 
It is a reserved word. If you do not want to rename the field just put brackets around the name.

str = "INSERT INTO prtinvoice (Qty,[Desc],Rate,Amount) VALUES('" & tempqty(i) & "','" & tempdesc(i) & "','" & temprate(i) & "','" & tempamount(i) & "')"

Swi
 
Thanks for the tip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top