我想从访问
中检索图像的路径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);
但在最后一行中发生了如下错误:条件表达式中的数据类型不匹配。
答案 0 :(得分: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);
我希望这会有所帮助。