DataTable.Expressions really not working

  • Thread starter Thread starter Tarun Mistry
  • Start date Start date
T

Tarun Mistry

Hi all, I have a DataTable im trying to filter, however I simply cannot get
what appears to be a simply expression to work.

Int cartId = 15;
string expression = "cartId =" + cartId;
DataRow[] test = myDataTable.Select(expression);

This always returns no datarows. However, if I hard code the expression
("cartId = 15") it works fine. How can I get my parameter to work?? i have
tried Convert.ToInt32(...), etc etc. The datatype is Int32.

Please help.

Kind regards
Taz
 
First, does the code you have even work. You are not casting cartId to
string and C# should not compile a non-explicit string conversion. Debug and
check your expression and you might find your problem.

ANother way of doing what you desire is a DataView with a filter expression.
It is not that much different and allows you to bind the same raw data to
many different controls.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
Back
Top