【问题标题】:INSERT INTO statement for Access in ASP.NETASP.NET 中 Access 的 INSERT INTO 语句
【发布时间】:2010-12-03 16:37:02
【问题描述】:

我正在开发一个网站。

我在 web.config 中的连接字符串如下:

"add name="MyDbConn1" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\QWIN 2000Q\Database\qwin_5501q.mdb;""

我已经使用该连接字符串从该数据库中检索了几次。他们正在工作。

但是当我插入一个表时,错误弹出“INSERT INTO 语句中的语法错误”。

下面是我插入语句的代码。

command2.Parameters.AddWithValue("@Name", txtUser.Text);
command2.Parameters.AddWithValue("@Password", txtPwd.Text);
command2.Parameters.AddWithValue("@Role", ddlAccess.SelectedItem.ToString());
string abc = "Insert into Report_User (Name, Password, Role) VALUES (@Name,@Password,@Role);";

当我在 Microsoft Access 中运行该语句时,没有错误。

有人吗?

有没有文件夹共享权限之类的??

【问题讨论】:

  • 先尝试不带参数的插入。您的参数之一可能无效。所以试试 string abc = "Insert into Report_User (Name, Password, Role) VALUES ('testName','testPassword,'testRole');";

标签: c# asp.net ms-access


【解决方案1】:

用特定于 OleDB 的参数占位符 ? 替换 SQL 参数名称 @Name

Insert into Report_User (Name, Password, Role) VALUES (?, ?, ?);

相应地更改command2.Parameters.Add(..)

【讨论】:

  • 其实就是“密码”。我改成“Pwd”就OK了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多