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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query results in dbgrid

Status
Not open for further replies.

rizunb

Programmer
Feb 27, 2003
63
CA
Hello people
I am kind of new to Delphi
I have sql server 200 backend.
what I am trying to do is after getting connected to sql server 2000, I want to run a query and show the results in DBGRID(not editable).
How do i do that using code.
I am able to a specific field in a text box.
I dont want to connect a whole table to the dbgrid, so that whenever u run m user can go edit the grid which will obviously edit the table.

I just need to show the results of a specific query in dbgrid(not letting ther user edit the grid)

I am sure you guyz can help
Thanks in advance
bye
 
It's pretty straight forward...

1. Drop a Tquery on your form. Connect it to your database directly or through your Tdatabase (or TConnection) component.

2. Add the SQL text into the TQuery's SQL property. Test the SQL by setting the TQuery's active property to true. If you get no errors, the SQL is fine and the connection to the DB is okay.

3. Drop a TDataSource component onto your form. Set the DataSet property of the data source to your TQuery component.

4. Drop a TDBGrid onto your form. Set the data source property of the grid to your data source component.

That's it, you should be able to see the query's result set in the grid. Don't get all hung up on the differences between the TTable and the TQuery type components. If you know how to access a table and you know SQL, then the TQuery is really straight forward. Think of a TTable as a TQuery with a "select * from..." SQL statement. The result set of a query has most of the same features as the result set of a table.

Lee.
 
To make the grid non-editable(in addition to what LelandS wrote), modify the Options property of the grid.

What you'll probably want to have set to True are: dgTitles, dgIndicator, dgRowSelect, dgAlwaysShowSelection.

You WILL want set to false: dgEditing and dgAlwaysShowEditor.

Any of the other options can be chosen or not based on what you want your grid to look like.

-D
 
If you want to make the DbGrid editable using a query, you have to set requestlive true By default the Query is non-editable.

Steven van Els
SAvanEls@cq-link.sr
 
To make the grid non-editable(in addition to what LelandS wrote), modify the Options property of the grid.

What you'll probably want to have set to True are: dgTitles, dgIndicator, dgRowSelect, dgAlwaysShowSelection.

You WILL want set to false: dgEditing and dgAlwaysShowEditor."

Can you change dgTitles to True/False at runtime ? thanks


 
While the existing delphi DBgrid will work, I have been using a grid from Developer Express. Their grid is similar to Outlook and has options for grouping, summing, sorting, printing all built in. It makes an ordinary data set look real nice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top