OleDbCommand:SQL 语法错误

发布于 2024-08-02 07:44:50 字数 583 浏览 2 评论 0原文

我在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-08-09 07:44:50

我认为您不能使用 SQL 和访问权限重命名列。

实现这一目标的最佳方法是使用新名称创建一个新列,更新新列并删除旧列。

ALTER  TABLE [Big List] ADD COLUMN [num] YOURTYPE;
UPDATE [Big List] SET [num] = [test];
ALTER  TABLE [Big List] DROP COLUMN [test];

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 [Big List] ADD COLUMN [num] YOURTYPE;
UPDATE [Big List] SET [num] = [test];
ALTER  TABLE [Big List] DROP COLUMN [test];
秋心╮凉 2024-08-09 07:44:50

尝试 ALTER TABLE [大列表] ALTER COLUMN [num] [test] CHARACTER

Try ALTER TABLE [Big List] ALTER COLUMN [num] [test] CHARACTER

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文