2

I have a dataview that contains a list of tables. I am reading in a list of values that I then want to apply as a filter to this dataview. The list of values is actually in the form of "table1, table2, table3". So I thought I would be able to use this as a filter on my dataview.

SqlOp.CommandText = "select name from dbo.sysobjects where xtype='u'";
SqlOp.ExecuteDataReader();
DataView dv = SqlOp.GetDataAsDataView();
SqlOp.CloseConnection();

Returns a list of all the tables in a dataview. Any help on how to filter this dataview?

Edit:
Not sure if I was completely clear in what I seek to accomplish. To clarify, I am trying to figure out how/if .RowFilter will help me in filtering this dataview. Something like:

dv.RowFilter = "name IN (table1, table2, table3)"    // I know this doesn't work
IAbstract
  • 19,551
  • 15
  • 98
  • 146

2 Answers2

1

You have to use like statement

"select name from dbo.sysobjects where xtype like 'u%'"

As well use Parameters collection

More Efficient Way of Adding Parameters to a SqlCommand .NET

Community
  • 1
  • 1
volody
  • 6,946
  • 3
  • 42
  • 54
  • I'm not entirely sure how the Parameters collection is intended to help me out in this situation. However, what I am trying to figure out is how to use the dataview's 'RowFilter'. – IAbstract May 25 '10 at 15:14
  • I did make the change to `like 'u%'` – IAbstract May 25 '10 at 15:19
  • Parameters collection will help from SQL Injection http://stackoverflow.com/questions/512174/non-web-sql-injection – volody May 25 '10 at 15:36
1

I figured out the .RowFilter issue:

dv.RowFilter = "name IN ('table1', 'table2', 'table3')    // missing the single quote surrounding table names
IAbstract
  • 19,551
  • 15
  • 98
  • 146