Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dataset Filter - Not supported?

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I found the following in the Delphi Help.

To create a filter using the Filter property, set the value of the property to a string that contains the filter’s test condition. For example, the following statement creates a filter that tests a dataset’s State field to see if it contains a value for the state of California:

Dataset1.Filter := 'State = ' + QuotedStr('CA');

You can also supply a value for Filter based on text supplied by the user. For example, the following statement assigns the text in from edit box to Filter:

Dataset1.Filter := Edit1.Text;

You can, of course, create a string based on both hard-coded text and user-supplied data:

Dataset1.Filter := 'State = ' + QuotedStr(Edit1.Text);


I have a form with a DBGrid and thousands of records. I have an edit box on the form for users to enter a name to search for when the 'SEARCH' button is pressed.

I have the following in my 'SEARCH' button on click:
Code:
procedure TfrmPriorServ.btnSearchFindClick(Sender: TObject);
begin
  JMSData.qrySearch.Datasource.DataSet.Filter:= 'LASTNAME = ' + QuotedStr(frmPriorServ.edLastNmCrit.Text);
end;

when i press the search button I get the Access Violation error.

Any clue what I'm doing wrong? The Filter property of the query is True.

Thanks! Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
I haven't worked much with queries, so pardon my ignorance in advance.

If you do want to filter your query, just say
Query.filter = ...

I'm guessing that you don't want to filter your query(which is also a tdataset), so does the query have a datasource that points to a ttable?

 
Do you also have a TTable component on your form? If the TDatasource component is not linked to something like a TTable or TQuery you will get an Access Violation error.

It is probably best to use the filter in your TTable component directly rather than go indirectly via the TDatasource component.

So your code would look something like:
Code:
procedure TfrmPriorServ.btnSearchFindClick(Sender: TObject);
begin
  JMSData.Table.Active := false;
  JMSData.Table.Filter:= 'LASTNAME = ' + QuotedStr(frmPriorServ.edLastNmCrit.Text);
  JMSData.Table.Filtered := true;
  JMSData.Table.Active := true;
end;


Andrew

 
I have a query (qrySearch), a dataset (dsSearch) and a DBGrid. The query returns thousands of records. I have an edit box and a Search button. I would like the user to enter the last name and press the search button and have the dataset filtered to the entered name. But I can't get it to work!

Thanks for the help! Any other suggestions?

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Hello.

I usually first open the table then set filtered to true but I don't think that's the problem. What I would do is create new project, with only the TQuery(and set the SQL property), TDataSource, TDBGrid and the Button with its OnClick code. That should help isolate the problem if you have a lot more code in the other project. Lets see if you then still get the AV.

Goodluck!
 
Leslie

I am confused.

When you say you have a "dataset (dsSearch)" what do you actually mean?

Do you have a TDataSource on your form? If not, how do you get data into your DBGrid?

When you say you can't get it to work do you mean you still get Access Violations?

Andrew
 
Yes I have a TDataSource attached to the DBGrid.

But I'm not at work right now so I'm relying on memory (and I've slept since then!). I think I may have a thought, I'll try it Monday and get back in touch if I need more assistance.

Thanks for the thought provoking responses (literally!!) Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top