OleDbDataReader inside a OleDbDataReader



我有2个表。我想从表1中获得所有的ID,而我在第一个OleDbCommand我想检查ID是否在表2中。我试过了:

using (OleDbCommand cmd = new OleDbCommand("SELECT ID FROM Table1 WHERE NAME=:NAME)
{
 ............
   decimal dId = (decimal)odr["ID"];
   using (OleDbCommand cmdE = new OleDbCommand("SELECT LOGID FROM Table2 WHERE ID:=ID", con))
   cmdE.CommandType = CommandType.Text;
   cmdE.Parameters.Add(new OleDbParameter("ID", dId));
   decimal cId=-1;
   using (OleDbDataReader odrE = cmdE.ExecuteReader())
   {
    while (odrE.Read())
    {
     cId = (decimal)odrE["ID"];
    }...............

问题是

 cId = (decimal)odrE["ID"]; 

永远不会执行,即使我在Sql Developer中执行手动选择,我也会得到结果。我做错了什么?

这是OLEDB中参数的错误语法。试着

using (OleDbCommand cmdE = new OleDbCommand("SELECT LOGID FROM Table2 WHERE ID=@ID", con))

我认为问题是在OleDbCommand中使用OleDbCommand。使用OUTER JOIN解决了这个问题。谢谢你

相关内容

  • 没有找到相关文章

最新更新