DAO query by array long[] numbers
-
I made a program using CDaoRecordSet with ACCESS97 database. And I want to query table data by array long[] that I have. long IDID[5]={7, 12, 14, 27, 33}; and I want to Do like this. CString ralp; //ID2 is a feild name of the table is named move in xx.mdb ralp.Format("ID2 LIKE %ld OR %ld OR %ld OR %ld OR %ld",IDID[0],IDID[1],IDID[2],IDID[3],IDID[4],IDID[5]"); m_pSet->m_strFilter=ralp; m_pSet->Requery(); But it goes wrong, it has just a one record though it must have 5. I want to query by my known numbers. Please help me. thanks.
-
I made a program using CDaoRecordSet with ACCESS97 database. And I want to query table data by array long[] that I have. long IDID[5]={7, 12, 14, 27, 33}; and I want to Do like this. CString ralp; //ID2 is a feild name of the table is named move in xx.mdb ralp.Format("ID2 LIKE %ld OR %ld OR %ld OR %ld OR %ld",IDID[0],IDID[1],IDID[2],IDID[3],IDID[4],IDID[5]"); m_pSet->m_strFilter=ralp; m_pSet->Requery(); But it goes wrong, it has just a one record though it must have 5. I want to query by my known numbers. Please help me. thanks.
Personally, I'd use "ID2 IN (%ld,%ld,%ld,%ld)" but then, I'm picky. The requery is likely to fail anyway, since (1) LIKE is applied to a string field, NOT a numeric type, and (2) the syntax should be ID2 LIKE 'x' OR ID2 LIKE 'y' OR ID2 LIKE 'z' Be aware that there is an upper limit (although I forget what) as to how many elements you can put in an IN clause. Using IN is more convenient if there isn't a fixed number of elements, since you can append ",value" data easily. Steve S