OleDbCommand:SQL 语法错误
我在尝试在 C# 项目中的 MS Access 数据库上使用 ALTER TABLE 命令时遇到问题。我正在尝试重命名列并同时更改类型。
这是我的命令:
string sqlCommand = "ALTER TABLE " + tableName + " CHANGE [" + oldColName + "] ["
+ newColName + "] " + colType;
这个命令有什么问题,我需要做什么才能使它工作?
*编辑:
-表、新列和旧列的类型和名称是不是问题!
- 捕获的异常是:
ALTER TABLE 语句中存在语法错误。
- 最终的字符串如下所示:
ALTER TABLE [大列表]更改[num] [test]字符
- 连接提供商:
微软.ACE.OLEDB.12.0
I am having trouble with a ALTER TABLE command that I am trying to use on a MS Access database in a C# project. I am trying to rename a column and change the type at the same time.
Here is my command:
string sqlCommand = "ALTER TABLE " + tableName + " CHANGE [" + oldColName + "] ["
+ newColName + "] " + colType;
What is wrong in this command and what do I need to do to make this it work?
*Edits:
-The type and the names of the table, new column and old column are not the problem!
-The exception that is catched is :
Syntax error in ALTER TABLE statement.
-The final string looks like this:
ALTER TABLE [Big List] CHANGE [num] [test] CHARACTER
-Connection provider:
Microsoft.ACE.OLEDB.12.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不能使用 SQL 和访问权限重命名列。
实现这一目标的最佳方法是使用新名称创建一个新列,更新新列并删除旧列。
I don't think you can rename a column with SQL and access.
The best way to achieve this is to create a new column with the new name, update the new column and drop the old one.
尝试 ALTER TABLE [大列表] ALTER COLUMN [num] [test] CHARACTER
Try ALTER TABLE [Big List] ALTER COLUMN [num] [test] CHARACTER