DataAdapter SQL Question

S

Steve Bishop

I'm using a DataSet object and binding it to a data grid. I would like
to filter the records I display by using a text box. I'm trying not to
take a literal string value but a wild card. I would like to take the
users first 3 characters and then search for the records that have the
closest matches.

I have a strSQL statement referenced in my DataAdapter. Could I do this
by adding a WHERE clause with LIKE in my SQL statement?

What would be the syntax if I referenced the text box value on my form
using a wild card? I am using C#. Help appreciated. Thanks.

Steve
 
R

Rahul Anand

You can use RowFilter property of a DataView object
derived from DataSet to filter rows based on some
conditions. In the filter expression you can specify
wildcards also.

For reference check this link:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemdatadataviewclassrowfiltertopic.as
p

You can also create your SQL query dynamicaly with the
LIKE clause. But for efficiency I will recommend using row
filter property of DataView, as it will not query database
every time.

Hope it will help.
 
G

Guest

Use this

string Filter = "GRID_COLUMN_NAME LIKE '" + txtProduct.Text + "*'";
DataSet.Tables[0].DefaultView.RowFilter = Filter; //assuming you have only 1 table in your datase
DataSet.Tables["TableName"].DefaultView.RowFilter = Filter; //assuming you have defined your tables in your datase

Works just fine!!
 

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

Top