Solved

DBGrid(c++)

Posted on 2000-04-08
6
886 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 112
Help on project with Soap 10 70
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 221
QuickReport, Delphi, Shape 12 47
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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