VB.Net - 无法创建字段“密码”在访问中
'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
我得到:字段定义中的语法错误, 当我尝试创建“密码”字段时。 在所有其他情况下(其他字段名称)它工作正常。
当尝试使用 MS-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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试“添加列[”&字段名 & "] "
密码是保留字。
Try "ADD COLUMN [" & fieldname & "] "
Password is a reserved word.
password
是 Jet 数据库引擎的关键字。您应该通过将其放在大括号中来转义它:[password]
。password
is a keyword for the Jet database engine. You should escape it by putting it in braces:[password]
.