DataView

R

Randy

Hello All,
I'm trying to use a DataView and in the rowfilter, base it on two fields in
the table. I can't find any examples on this. Is there a way to do it. I'm
talking about something like...
DataView dv = new DataView(myTable,
"field1 like '" + buffer + "*' and field2 = true",
"field1",
DataViewRowState.CurrentRows);
The above doesn't seem to work. I'm not sure if I'm supposed to use the
"and" in it...also I'm not sure how to do the boolean check for true in the
rowfilter.
One of my fields is a boolean (checkbox) and I need to pull only records
where it is true, but I can't find any examples on this either. Does anyone
know how to do this?
Thanks
Cheers :)
 
W

William Ryan eMVP

Randy:
You can definitely use AND in between them and you if it's a Bit column in
the db for instance, or something that definitely evaluates to T/F , you
should be fine. Here's a sample that works:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged

dvvv.RowFilter = "Exempt = true AND EmplNum > 100"

' dvvv.RowFilter = "Exempt = 1 and EmplNum > 100" Produces same result as
above.

Label1.Text = dvvv.Count.ToString

End Sub

Dim dvvv As DataView

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim ddd As New DataSet

SqlDataAdapter2.Fill(ddd, "test")

dvvv = ddd.Tables(0).DefaultView

DataGrid1.DataSource = dvvv

Label1.Text = dvvv.Count.ToString

End Sub
 
R

Randy

William,
Thanks for the input. I thought that was how you do it. Then I was on the
right track. I looked over your example below and I tried both ways...with
true and 1, and it still doesn't work. I've tried both of these ways...
DataView dv = new DataView(masterDataSet.Tables["residue_data"],
"tox_effect like '" + tbuff + "*' and CheckBox1 = true",
"tox_effect",
DataViewRowState.CurrentRows);

I"ve also tried this way...
DataView dv = new DataView(masterDataSet.Tables["residue_data"],
"tox_effect like '" + tbuff + "*' and CheckBox1 = " + true + "",
"tox_effect",
DataViewRowState.CurrentRows);

and it still returns 0 records. When I take out the "and CheckBox1 = true"
part and just check tox_effect, the LIKE part works...strange.
 
R

Randy

I think I see the problem...I don't have a event handler to handle when I
click (set) the check box to true...so, later when I try and create a
dataview on true values...none are true.
Any idea on how to set up an event on a checkbox in a datagrid?
Thanks

Randy said:
William,
Thanks for the input. I thought that was how you do it. Then I was on the
right track. I looked over your example below and I tried both ways...with
true and 1, and it still doesn't work. I've tried both of these ways...
DataView dv = new DataView(masterDataSet.Tables["residue_data"],
"tox_effect like '" + tbuff + "*' and CheckBox1 = true",
"tox_effect",
DataViewRowState.CurrentRows);

I"ve also tried this way...
DataView dv = new DataView(masterDataSet.Tables["residue_data"],
"tox_effect like '" + tbuff + "*' and CheckBox1 = " + true + "",
"tox_effect",
DataViewRowState.CurrentRows);

and it still returns 0 records. When I take out the "and CheckBox1 = true"
part and just check tox_effect, the LIKE part works...strange.


William Ryan eMVP said:
Randy:
You can definitely use AND in between them and you if it's a Bit column in
the db for instance, or something that definitely evaluates to T/F , you
should be fine. Here's a sample that works:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
ByVal
e
As System.EventArgs) Handles CheckBox1.CheckedChanged

dvvv.RowFilter = "Exempt = true AND EmplNum > 100"

' dvvv.RowFilter = "Exempt = 1 and EmplNum > 100" Produces same result as
above.

Label1.Text = dvvv.Count.ToString

End Sub

Dim dvvv As DataView

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim ddd As New DataSet

SqlDataAdapter2.Fill(ddd, "test")

dvvv = ddd.Tables(0).DefaultView

DataGrid1.DataSource = dvvv

Label1.Text = dvvv.Count.ToString

End Sub

fields
in in
the
 

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