我正在
“没有给出一个或多个必需参数的值”
从下面的代码看起来一切都很好找不到问题。
string myConnectionString= @"Provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\TiptonDB.mdb";
string query = "SELECT NodeID FROM NDDINodes";//"SELECT O.NodeID, N.NodeID FROM NDDINodes AS N, NDDINodes AS O WHERE N.X=O.X And N.Y=O.Y And N.NodeID<>O.NodeID";
DataSet dt = new DataSet();
using (OleDbConnection myConnection = new OleDbConnection())
{
myConnection.ConnectionString=myConnectionString;
OleDbCommand cmd=new OleDbCommand ();
cmd.Connection=myConnection;
// cmd.CommandText="SELECT O.NodeID, N.NodeID FROM NDDINodes AS N, NDDINodes AS O WHERE N.X=O.X And N.Y=O.Y And N.NodeID<>O.NodeID";
myConnection.Open();
OleDbDataAdapter ad = new OleDbDataAdapter(query,myConnection);
ad.Fill(dt);
}
答案 0 :(得分:0)
只需在代码中添加
即可 OleDbDataAdapter ad = new OleDbDataAdapter();
ad.SelectCommand = new OleDbCommand(query, myConnection);
答案 1 :(得分:0)
string myConnectionString= @"Provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\TiptonDB.mdb";
string query = "SELECT NodeID FROM NDDINodes";//"SELECT O.NodeID, N.NodeID FROM NDDINodes AS N, NDDINodes AS O WHERE N.X=O.X And N.Y=O.Y And N.NodeID<>O.NodeID";
DataSet dt = new DataSet();
OleDbConnection objXConn = new OleDbConnection(myConnectionString);
objXConn.Open();
OleDbCommand objCommand = new OleDbCommand(query, objXConn);
OleDbDataAdapter adp = new OleDbDataAdapter(objCommand);
adp.Fill(dt);
objXConn.Close();
答案 2 :(得分:0)
确保您的连接字符串不缺少数据:UserName/Password
,Persist Security Info=True
,...
Check this link用于访问connectionString设置。