我一直在尝试使用OleDb向我的excel文件发送一个选择查询,但是我得到的例外情况是“没有给出一个或多个必需参数的值”
这是我的代码:
using (var scon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=YES;\""))
{
scon.Open();
var param = obj.data.Replace("*", "");
var scom = new OleDbCommand("SELECT * FROM [AAA$] WHERE [HDRNAME] <> '"+param+"'", scon);
var sqr = scom.ExecuteReader();
var newobj = new dboject();
while (sqr.Read())
{
Thread.Sleep(5);
newobj.data = sqr[2].ToString();
break;
}
return newobj;
}
}
我在这一行得到例外:
var sqr = scom.ExecuteReader();
我也尝试过使用excel单元名称而没有标题,但这次它只是忽略where子句并获取所有内容。
代码:
using (var scon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=NO;\""))
{
scon.Open();
var param = obj.data.Replace("*", "");
var scom = new OleDbCommand("SELECT * FROM [AAA$] WHERE [F5] <> '"+param+"'", scon);
var sqr = scom.ExecuteReader();
var newobj = new dboject();
while (sqr.Read())
{
Thread.Sleep(5);
newobj.data = sqr[2].ToString();
}
return newobj;
}
}
由于