简体   繁体   中英

VB.Net - Cannot create field “password” in Access

'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???

Try "ADD COLUMN [" & fieldname & "] "

Password is a reserved word.

password is a keyword for the Jet database engine. You should escape it by putting it in braces: [password] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM