gpt4 book ai didi

c# - System.Data.OleDb.OleDbException 需要一个或多个参数

转载 作者:行者123 更新时间:2023-11-29 10:44:49 28 4
gpt4 key购买 nike

我使用 Visual Studio Enterprise 2015 WPF 来完成我的项目,我的数据库是一个 ms access 文件我不确定为什么会出现此错误有人可以

System.Data.dll 中发生“System.Data.OleDb.OleDbException”类型的未处理异常
附加信息:没有为一个或多个必需参数给出值。

这是我的代码

OleDbConnection con = new OleDbConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select `Name1`,`ID` from `Employee` WHERE `Name1` = Jacob ";
cmd.Connection = con;
OleDbDataReader rd = cmd.ExecuteReader();
grid1.ItemsSource = rd;

我也尝试过

OleDbConnection con = new OleDbConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select Name1,ID from [Employee] WHERE Name1 = Jacob ";
cmd.Connection = con;
OleDbDataReader rd = cmd.ExecuteReader();
grid1.ItemsSource = rd;


OleDbConnection con = new OleDbConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select * from [Employee] WHERE Name1 = Jacob ";
cmd.Connection = con;
OleDbDataReader rd = cmd.ExecuteReader();
grid1.ItemsSource = rd;

但还是同样的错误

我的连接字符串

<connectionStrings>
<add name="Connection" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\wpfdb.accdb;Persist Security Info=False;"/>

最佳答案

在您的命令文本行中,例如:

> cmd.CommandText = "select `Name1`,`ID` from `Employee` WHERE `Name1` =
> Jacob ";

Jacob 需要用引号引起来,而不是列名和表名:

cmd.CommandText = "select * Employee WHERE Name1 = 'Jacob' ";

关于c# - System.Data.OleDb.OleDbException 需要一个或多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44793113/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com