Solved

DBGrid(c++)

Posted on 2000-04-08
6
887 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
Independent Software Vendors: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

623 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