-1

I have 2 Tables. I want to get all ID's from Table1, and while I am inside the frist OleDbCommand I want to check if the ID is in Table2 too. I tried this:

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"];
    }...............

The Problem is that

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

is never executed, even though if I do a manaul Select inside the Sql Developer i get results. What am I doing wrong?

user576914
  • 199
  • 1
  • 8
  • 22

2 Answers2

0

That's the wrong syntax for parameters in OLEDB. Try

using (OleDbCommand cmdE = new OleDbCommand("SELECT LOGID FROM Table2 WHERE ID=@ID", con))
John Saunders
  • 160,644
  • 26
  • 247
  • 397
0

I think the problem is using a OleDbCommand inside a OleDbCommand. Using a OUTER JOIN solved the problem. Thank you

user576914
  • 199
  • 1
  • 8
  • 22