0

我想从访问中检索图像的路径

DataTable myTable = new DataTable();
OleDbConnection myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

OleDbCommand myCommand = new OleDbCommand();
myCommand.CommandText = "SELECT ImageName AS 'ImageName', ImagePath AS 'Path' FROM [AImages]  WHERE ID='" + _ID + "'";
myCommand.CommandType = CommandType.Text;
myCommand.Connection = myConnection;

OleDbDataAdapter myAdapter = new OleDbDataAdapter();

myAdapter.SelectCommand = myCommand;
myAdapter.Fill(myTable);

但在最后一行发生了这样的错误:标准表达式中的数据类型不匹配。

4

1 回答 1

0

我怀疑问题出在你传递 ID 的方式上,也许你可以试试这个:

// note the ID=?
myCommand.CommandText = "SELECT ImageName AS 'ImageName', ImagePath AS 'Path' FROM [AImages]  WHERE ID=?";
myCommand.CommandType = CommandType.Text;

// now a parameter
var pId = new OleDbParameter {Value = _ID};
myCommand.Parameters.Add(pId);

我希望这有帮助。

于 2013-05-20T07:33:41.973 回答