Filter records in a form...

  • Thread starter Thread starter Jan Nielsen
  • Start date Start date
J

Jan Nielsen

Hi
I have a databound form with "person data" (ie first name, surname, gender)
that is bound to a dataset.
I would like to filter the form so it only shows persons with gender =
"Boy".
I have tried to edit the sqlDataAdapter.Selectcommand.commandtext and then
use sqlDataadapter.Fill(MyOriginalDataSet,"OriginalTable")
But this does not reflect in the form. Even though the SQL seems to be
correct.

Then I tried a dataview
DvFind.RowFilter = "Gender = 'boy'
This returns the correct records but is not reflected in the form

Can anyone help?

Best regards

Jan
 
The select command is going to bring back some data records only flitered by
the Where Clause.

If you want to filter the data client side, you can use a DatavView for
instance and set it's rowfilter..
dv = dsMain.Tables[0].DefaultView;

dg.DataSource = dv;

dg.DisplayMember = "Title_Description";

dv.RowFilter = "Work_Type = '0'";

//This below will set the filter....


dv.RowFilter = "Work_Type = '" + s + "'";


btnSelect.Enabled = true;
 
Hi William
Thanks for answering.
I want to return data records only filtered by the where clause.

But your answer is assuming I use a datagrid. I don't.
I use a form with databound textboxes.

I fill the dataadapter with all records from the beginning, but I would like
to be able to filter these records at runtime. Like Microsoft Access does.

Best regards

Jan


William Ryan said:
The select command is going to bring back some data records only flitered by
the Where Clause.

If you want to filter the data client side, you can use a DatavView for
instance and set it's rowfilter..
dv = dsMain.Tables[0].DefaultView;

dg.DataSource = dv;

dg.DisplayMember = "Title_Description";

dv.RowFilter = "Work_Type = '0'";

//This below will set the filter....


dv.RowFilter = "Work_Type = '" + s + "'";


btnSelect.Enabled = true;

Jan Nielsen said:
Hi
I have a databound form with "person data" (ie first name, surname, gender)
that is bound to a dataset.
I would like to filter the form so it only shows persons with gender =
"Boy".
I have tried to edit the sqlDataAdapter.Selectcommand.commandtext and then
use sqlDataadapter.Fill(MyOriginalDataSet,"OriginalTable")
But this does not reflect in the form. Even though the SQL seems to be
correct.

Then I tried a dataview
DvFind.RowFilter = "Gender = 'boy'
This returns the correct records but is not reflected in the form

Can anyone help?

Best regards

Jan
 
It seems like I just needed to add
MyDataSet.MyTable.Clear()
before the dataadapter.fill

Best regards

Jan


William Ryan said:
The select command is going to bring back some data records only flitered by
the Where Clause.

If you want to filter the data client side, you can use a DatavView for
instance and set it's rowfilter..
dv = dsMain.Tables[0].DefaultView;

dg.DataSource = dv;

dg.DisplayMember = "Title_Description";

dv.RowFilter = "Work_Type = '0'";

//This below will set the filter....


dv.RowFilter = "Work_Type = '" + s + "'";


btnSelect.Enabled = true;

Jan Nielsen said:
Hi
I have a databound form with "person data" (ie first name, surname, gender)
that is bound to a dataset.
I would like to filter the form so it only shows persons with gender =
"Boy".
I have tried to edit the sqlDataAdapter.Selectcommand.commandtext and then
use sqlDataadapter.Fill(MyOriginalDataSet,"OriginalTable")
But this does not reflect in the form. Even though the SQL seems to be
correct.

Then I tried a dataview
DvFind.RowFilter = "Gender = 'boy'
This returns the correct records but is not reflected in the form

Can anyone help?

Best regards

Jan
 
You don't need to use a Datagrid, that was just the example I used. The
Dataview is what's filtered there data.
Jan Nielsen said:
Hi William
Thanks for answering.
I want to return data records only filtered by the where clause.

But your answer is assuming I use a datagrid. I don't.
I use a form with databound textboxes.

I fill the dataadapter with all records from the beginning, but I would like
to be able to filter these records at runtime. Like Microsoft Access does.

Best regards

Jan


William Ryan said:
The select command is going to bring back some data records only
flitered
by
the Where Clause.

If you want to filter the data client side, you can use a DatavView for
instance and set it's rowfilter..
dv = dsMain.Tables[0].DefaultView;

dg.DataSource = dv;

dg.DisplayMember = "Title_Description";

dv.RowFilter = "Work_Type = '0'";

//This below will set the filter....


dv.RowFilter = "Work_Type = '" + s + "'";


btnSelect.Enabled = true;

Jan Nielsen said:
Hi
I have a databound form with "person data" (ie first name, surname, gender)
that is bound to a dataset.
I would like to filter the form so it only shows persons with gender =
"Boy".
I have tried to edit the sqlDataAdapter.Selectcommand.commandtext and then
use sqlDataadapter.Fill(MyOriginalDataSet,"OriginalTable")
But this does not reflect in the form. Even though the SQL seems to be
correct.

Then I tried a dataview
DvFind.RowFilter = "Gender = 'boy'
This returns the correct records but is not reflected in the form

Can anyone help?

Best regards

Jan
 
Yes, but a form does not have a .datasource property
My question was how to "connect" a dataview with a form
But I found the answer myself.

Jan
William Ryan said:
You don't need to use a Datagrid, that was just the example I used. The
Dataview is what's filtered there data.
Jan Nielsen said:
Hi William
Thanks for answering.
I want to return data records only filtered by the where clause.

But your answer is assuming I use a datagrid. I don't.
I use a form with databound textboxes.

I fill the dataadapter with all records from the beginning, but I would like
to be able to filter these records at runtime. Like Microsoft Access does.

Best regards

Jan


William Ryan said:
The select command is going to bring back some data records only
flitered
by
the Where Clause.

If you want to filter the data client side, you can use a DatavView for
instance and set it's rowfilter..
dv = dsMain.Tables[0].DefaultView;

dg.DataSource = dv;

dg.DisplayMember = "Title_Description";

dv.RowFilter = "Work_Type = '0'";

//This below will set the filter....


dv.RowFilter = "Work_Type = '" + s + "'";


btnSelect.Enabled = true;

Hi
I have a databound form with "person data" (ie first name, surname,
gender)
that is bound to a dataset.
I would like to filter the form so it only shows persons with gender =
"Boy".
I have tried to edit the sqlDataAdapter.Selectcommand.commandtext
and
then
use sqlDataadapter.Fill(MyOriginalDataSet,"OriginalTable")
But this does not reflect in the form. Even though the SQL seems to be
correct.

Then I tried a dataview
DvFind.RowFilter = "Gender = 'boy'
This returns the correct records but is not reflected in the form

Can anyone help?

Best regards

Jan
 
Hi Jan,
You are learning fast.

Got my problems solved too.

Did not tell you but also the sequence you assign your datasets to the
bindings if very important.

Nothing to do with this but with the problems we had. But maybe you did
recognise that yourself already, because as I said, you are learning fast in
the Net.

:-)

Cor
 
Hi Cor
Thanks for the nice words!

Why is the binding sequence important?
Is that important for the Databindings.Item(?) reference?

I would like to add a menuitem to my contextmenu that sorts the selected
field ascending or descending.
I can dynamically build the SQL and insert it into the dataadapters
Selectcommand like I did with the filter thing, but I would like to use a
dataview if this is possible. (If it is possible it seems like it would be
easier.)
I just cannot find a way to bind the forms bindingcontext to the dataview.
Do you know if this is possible?

***************************
(Btw here is some code to move the cursor to the selected control if you
rightclick on a control with a contextmenu
Private Sub ContextSortFilter_Popup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ContextSorterFiltrer.Popup
Dim RightClickedControl As String

RightClickedControl = sender.sourcecontrol.name()

Dim Myindex As Integer

Myindex = Me.Controls.GetChildIndex(sender.sourcecontrol)

Me.Controls(Myindex).Focus()

End Sub

*******************************

Jan
 
Hi Jan,

As example, when you bind to fast to a control with an index, all things you
do with that binding can affect the index changed so you see a lot of
actions.

So add the binding the control at the latest moment when all dings are done
about the that will be done once.
Cor
 
Back
Top