开发者

How to filter a dataview

开发者 https://www.devze.com 2022-12-31 19:23 出处:网络
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, table

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. S开发者_StackOverflowomething like:

dv.RowFilter = "name IN (table1, table2, table3)"    // I know this doesn't work


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


I figured out the .RowFilter issue:

dv.RowFilter = "name IN ('table1', 'table2', 'table3')    // missing the single quote surrounding table names
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号