G
Guest
I have a data application that has been working for years on MS Access and VBA.
In my application there are several grids with search capabilities (based on
the ADO recordset.find method) which are provided by a separate form that
allows:
a) To type and/or select search criteria from a combo box
b) To select the field where the criteria will be searched
c) To select the type of match desired (the criteria could be found at the
begining of the field, in any part of the field or should match the whole
field). I use wildcards to build the search criteria. For example:
strCriteria = "[" & strField & "] Like '" & strCrit & "*'"
d) To find the first matching record (Find First). Regardless of the grid
sorting order, the cursor stops on the first matching record to the user's
eyes.
e) To find all other matching records (Find Next), using the ADO
recordset.bookmark property to set the starting record for the find action.
I am trying to upgrade my application to SQL Server 2005 and Visual basic
..Net 2005.
In my VB .Net 2005 application:
I have a datagridview with a datatable as datasource.
To reproduce the search capabilities:
I tried to use the datatable.defaultview.find method.
The problem here is that this dataview.find method does not support the
use of wildcards or searching from a position other than the begining of the
dataview.
I thought that the datatable.select method could help, and it does, but I
still find limitations:
I use the datatable.select method with wildcards in the search criteria to
get a datarow array of matching rows.
Then I can traverse the datarow array and, for each datarow in the array,
I retrieve the whole content of the searched column
I use this content with the datatable.dataview.find method to get the
index of the matching row.
I use a currencymanager to select the desired row in the datagridview.
The limitations with this approach are:
If the searched column is not a primary key, there could be several
datarows with exactly the same value in that column. In this case, the
datatable.dataview.find method will never get to the second or third matching
datarows, it will always stop at the first one. The Find Next action does not
work.
In order to use the datatable.dataview.find method I have to set the
datatable.dataview.sort property and in doing this I risk changing the
datagridview sorting to the eyes of the user, and I am sure the user will not
like it.
To solve the afore mentioned limitations I thought about retrieving the
primary key values for each row in the datarow array and use the primary
key(1) with the datatable.dataview.find method. Now the Find Next action
works fine. But...
I have to set the datatable.dataview.sort property to the primary key,
affecting the grid sorting to the eyes of the user.
After 4 or 5 days of searching, reading, trying and failing, I am running
out of ideas to solve this problem, can anyone help?
Thanks,
(1) I had to recreate the primary key, even though the table in the database
has it already defined. The datareader does not retrieve the primery key
property of the table. Should I use a dataset instead of a datareader?
In my application there are several grids with search capabilities (based on
the ADO recordset.find method) which are provided by a separate form that
allows:
a) To type and/or select search criteria from a combo box
b) To select the field where the criteria will be searched
c) To select the type of match desired (the criteria could be found at the
begining of the field, in any part of the field or should match the whole
field). I use wildcards to build the search criteria. For example:
strCriteria = "[" & strField & "] Like '" & strCrit & "*'"
d) To find the first matching record (Find First). Regardless of the grid
sorting order, the cursor stops on the first matching record to the user's
eyes.
e) To find all other matching records (Find Next), using the ADO
recordset.bookmark property to set the starting record for the find action.
I am trying to upgrade my application to SQL Server 2005 and Visual basic
..Net 2005.
In my VB .Net 2005 application:
I have a datagridview with a datatable as datasource.
To reproduce the search capabilities:
I tried to use the datatable.defaultview.find method.
The problem here is that this dataview.find method does not support the
use of wildcards or searching from a position other than the begining of the
dataview.
I thought that the datatable.select method could help, and it does, but I
still find limitations:
I use the datatable.select method with wildcards in the search criteria to
get a datarow array of matching rows.
Then I can traverse the datarow array and, for each datarow in the array,
I retrieve the whole content of the searched column
I use this content with the datatable.dataview.find method to get the
index of the matching row.
I use a currencymanager to select the desired row in the datagridview.
The limitations with this approach are:
If the searched column is not a primary key, there could be several
datarows with exactly the same value in that column. In this case, the
datatable.dataview.find method will never get to the second or third matching
datarows, it will always stop at the first one. The Find Next action does not
work.
In order to use the datatable.dataview.find method I have to set the
datatable.dataview.sort property and in doing this I risk changing the
datagridview sorting to the eyes of the user, and I am sure the user will not
like it.
To solve the afore mentioned limitations I thought about retrieving the
primary key values for each row in the datarow array and use the primary
key(1) with the datatable.dataview.find method. Now the Find Next action
works fine. But...
I have to set the datatable.dataview.sort property to the primary key,
affecting the grid sorting to the eyes of the user.
After 4 or 5 days of searching, reading, trying and failing, I am running
out of ideas to solve this problem, can anyone help?
Thanks,
(1) I had to recreate the primary key, even though the table in the database
has it already defined. The datareader does not retrieve the primery key
property of the table. Should I use a dataset instead of a datareader?