Solved

DBGrid(c++)

Posted on 2000-04-08
6
885 Views
Last Modified: 2006-11-17
Hi,(this is BBuilder c++ question)

How can I read data in containd in DBGrid ?
I wont to read for example all values which are in  field 2

I make it works with dbgrid navigator but that's to messy
I also have found  following line of code but it is for Delphi and for some reason it don't work

DBGrid1.Columns[4].Field.AsString
I try to do following
DBGrid1->Columns[2]->Field->AsString;
but it reports error.

This is how i made it with db navigator

for (int z=0;z<RecordCount;z++) {
   zbir = zbir +Form1->DBGrid1->Fields[2]->AsInteger;//I need to accumulate all values containd in all cells inside field[2]
      Form1->DBNavigator1->BtnClick(nbNext);//and move to next cell
  }

How can i acces this data's not using dbnavigator



0
Comment
Question by:xtvca
  • 4
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 2695973
for (int z=0;z<RecordCount;z++)???
whats are .... :o)

You do not need to manipulate with DBGrig, just do it with your DataSet.

Table1 -> first
while Table1 -> EOF do
begin
    SomeValue := Table1->Fields[2]->AsWhatYouWant;
   Table1->Next;
end;

----
Igor
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2695975
typo...
while not Table1-> EOF
0
 

Author Comment

by:xtvca
ID: 2695986
I'm not working with tables but with SQL query's
Thats why i need to read data from DBGrid (or is there is some better solution I wold be happy to hear (i'm still begginer))

Regards
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 9

Accepted Solution

by:
ITugay earned 19 total points
ID: 2696028
Just change Table1 to Query1 ;)

Now seriously. The code bellow is sample how to extract all fields value from given table.
--------
Query1 is TQuery;
ListBox1 is TListBox it will filled out by Query1.Fields[1] values;
-------

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
   Listbox1.Clear;  // clear content of ListBox
   Query1.Open;  // open query
   while not Query1.EOF do // do for all records in Query1
   begin
      ListBox1.Items.Add(Query1.Fields[1].AsString); // add first field value to ListBox
      Query1.Next; // goto next record
   end;
   Query1.Close; // close Query
end;

-----

To repeat this sample in your applcation drop TQuery, TListBox, TSpeedButton components on your form and copy/paste xode above to you OnButtonClick procedure.

------
Igor.

PS: it's Delphi, OK?
0
 

Author Comment

by:xtvca
ID: 2696141
GREAT IT WORKS

Line is :
ListBox1->Items->Add(Query1->Fields->Fields[2]->AsString); // add first field value to ListBox

THANKS
&REGARDS

0
 
LVL 9

Expert Comment

by:ITugay
ID: 2696148
;)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question