Like condition generate

May 9, 2012 at 3:52 AM


I want to select records which has same Customer_Code. I have used like condition, example "Customer_Code like '*208*'".

I have used DBQuery to generate SQL and executed on MS Access then it has returned correct records. 

But I have used DBDatabase to execute then results has been wrong.


string condition = string.Format("*{0}*", customerCode);
DBQuery sel = DBQuery.Select()
                     .Fields(CustomerScheme.CustomerCode, CustomerScheme.CustomerName, CustomerScheme.DeliveryAddr1,
                      CustomerScheme.DeliveryAddr2, CustomerScheme.Conact1, CustomerScheme.FreightRegion, CustomerScheme.AccountId, CustomerScheme.Conact1)
                      .WhereField(CustomerScheme.CustomerCode, Compare.Like, DBConst.String(condition));


Please help me,


Hien Phan


May 9, 2012 at 9:23 AM

If you are using MS Access then this should work.

For SQL Sever the wildcard character is '%'. Not sure if this is what you are attempting.

I'd also recommend changing the constant to a parameter if it is accepting user input.

DBParam condition = DBParam.ParamWithValue(string.Format("%{0}%",customerCode));


WhereField(CustomerScheme.CustomerCode, Compare.Like, condition));
If you are trying to run this against MS Access and it's failing, then I'll try to re-create the issue.

May 9, 2012 at 12:00 PM

Thank you,

It has worked. That's a cool library!