DataTable.Expressions really not working

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
 
C

Cowboy \(Gregory A. Beamer\)

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!
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top