PDA

View Full Version : VB 6.0 and SQL syntax error


Garon
02-02-2004, 01:49 PM
Hey,

I am trying to create a table in a *.mdb file with the following line of code:

Db.Execute ("CREATE TABLE " & txtCatName.Text & " (Index AUTONUMBER, PartName VARCHAR(50), PartDescription VARCHAR(300), PartPicLocation VARCHAR(100))")

I am getting a syntax error, not on the vb but the sql. I think that it is the part with the AUTONUMBER, but i am not sure :( and i havn't been able to find any usful help anywhere else that i have looked. Any help would be great.

fyrye
05-26-2004, 01:45 AM
mySQL = "Create Table " & fTableName & vbcrlf & _
"(" & vbcrlf & _
replace(fTableName, " ", "_") & "_ID int IDENTITY NOT NULL constraint" & vbcrlf & _
replace(fTableName, " ", "_") & "_ID PRIMARY KEY, " & vbcrlf
for x = 0 to Ubound(fColumnName)
if x <> Ubound(fColumnName) Then addcomma = ", "
mySQL = mySQL & fColumnName(x) & " " & fDataType(x) & " " & addcomma & vbcrlf
addcomma = ""
Next
mySQL = mySQL & _
")"

I have an automated script that creates tables for me autonumber and all, my column names and types are setup into an array and processed that way I added the VBcrlf so that the code will look neat should i write it to a textarea.