Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

Database question

Hi there!
I wonder, are there a way to read SQL data into a Treeview or Listview?
I've tried a lot, but do only get the SQL sentence written, instead of the extracted data.

Thanx in advance!
0
bear040497
Asked:
bear040497
1 Solution
 
MatveyCommented:
Automatic way ? No, I don't think so.

What do you mean by your last sentence ?
(Does your SQL request produces any data ?)
If you have your data from your request, what problem do you have with putting it in any visual way or into any kind of control ?
(Maybe you are new to Delphi ?)

Matvey
0
 
bear040497Author Commented:
Nope, I've used Delphi for about 1 1/2 year, but it's just recently that I've found that there is some special data base features that I need, which I know is not originally supported by Delphi. SO, I'm NOT new to Delphi.
This is how I do it:
I use a Table, a Datasource, and a Query object.
In the query, I have this statement: select * from <table>
I do also have a Listview, which I want to place the extracted data in, but all I get, is the SQL statement.
My question is: Is there a way to get this data from the data base table into the listview? All I get now, is the SQL sentence and NOT the data.

Thanx in advance!
0
 
mvz121697Commented:
I don't know what you mean with 'special database feature', but in my opinion there is no 'data-aware' listview.
But i'll try to answer your question in 2 way's:

1)
Have you tried using a TDBgrid ? Drop a TQuery, a TDatasource and a TDBGrid on your form.
In the object-inspector, set the Datasource1.dataset to Query1, the Dbgrid1.Datasource to Datasource1, select a databasename for Query1, and fill in a 'select * from <tablename> in the SQL-property. Then set the Query1.active to True, and you'll have your data in the Grid.

2)
 I think above story was too simple (because you are not new to Delphi. So you want the data in a TListView ? May be following will get you on the way:

var tLi:tlistitem;
begin

Query1.open;
Query1.First;
While (not Query1.eof) and (not Application.Terminated) do begin
   tLI:=ListView1.Items.Add;
   tLI.Caption:=(Query1.FieldByName('FieldName').Asstring);
   Query1.Next;
 end;
end;


0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now