Anjali5 Anjali5 - 11 days ago 5
ASP.NET (C#) Question

filtering out dataset to eliminate one value

I only have four values in my dataset:

Value1
Value2
Value3
Value4


I want to filter my dataset so that it only has Value1, value2 and Value3. I don't want value4 in my dataset and then I want to bind my drop down list with this dataset. Here is what I have so far:

Dim ds As New DataSet
ds = SelectionProdCriteria.GetCostType()
ds.Tables(0).DefaultView.RowFilter = "CostType=Value4"
ddlCostType.DataSource = ds
ddlCostType.DataValueField = "CostType"
ddlCostType.DataTextField = "CostType"
ddlCostType.DataBind()


I am getting an error at
ds.Tables(0).DefaultView.RowFilter = "CostType=Value4"
saying Missing Operand after support operator.

I just want to see value1, value2 and Value3 in my drop down list and filter out value4.

Any help will be appreciated.

mww mww
Answer

You can use Linq. Just get all element without Value4 like this:

Dim query = _
    From ct In  ds.Tables(0).AsEnumerable() _
    Where ct.Field(Of String)("CostType") != Value4
    Select ct 
Dim view As DataView = query.AsDataView()
ddlCostType.DataSource = view
ddlCostType.DataValueField = "CostType"
ddlCostType.DataTextField = "CostType"
ddlCostType.DataBind()
Comments