Reputation: 11053
'Create field in table
Public Sub createField(ByVal tableName As String, ByVal fieldName As String, ByVal fieldType As String)
If Not isConnected() Then
XGUI.consolePrint("XAccessDatabase.createField() Warning - Database not connected. Create field canceled")
Exit Function
End If
Dim myOleDbCommand As OleDbCommand
myOleDbCommand = New OleDbCommand("ALTER TABLE " & tableName & " ADD COLUMN " & fieldName & " " & fieldType, connection)
myOleDbCommand.ExecuteNonQuery()
End Function
createField("users", "password", "TEXT(60)") 'Password
I get: Syntax error in field definition, when I try to create "password" field. In all other cases (other field names) it works fine.
When trying to create it manually with MS-Access, I have no problem either. What is going on???
Upvotes: 1
Views: 560
Reputation: 1372
Try "ADD COLUMN [" & fieldname & "] "
Password is a reserved word.
Upvotes: 2
Reputation: 172200
password
is a keyword for the Jet database engine. You should escape it by putting it in braces: [password]
.
Upvotes: 2