Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 13th, 2012, 5:09 AM   #1
squills
Expert Programmer
 
squills's Avatar
 
Join Date: Feb 2009
Posts: 635
Rep Power: 6 squills is on a distinguished road
Exclamation counting rows in dbgrid

ok I have connected to a database pulled the data i needed and loaded it into a dbgrid. in the grid i have a collum called 'ERRORS' and it will contain codes like

WRis1
Yell2
BotRA
ect...

I would like to have it so after it runs the query and places data into grids. it will then count how many times each error is in the grid. I don't have a list of all the possible errors, as there is a huge amount So i guess it would have to create its own list of errors in the db, and then count those errors? Not sure really confused. here is how i added info to db if it helps?

adoquery1.Active := false;
tester := inputbox('Tester Data','Enter Tester asset','999/99/999');
sdate := inputbox('Tester Data','Enter start date','1/1/1990');
edate := inputbox('Tester Data','Enter end date','1/1/2012');
adoquery1.SQL.Text := 'Select * From [Main Table] WHERE [Tester] = "'+tester+'"  AND  [Date] BETWEEN #'+sdate+'# AND #'+edate+'#';
adoquery1.Active := true;

thanks
squills

EDIT..
also i know if i do this
showmessage(dbgrid1.Columns.Grid.Fields[8].DisplayText);

it will show me the error code of the first row only.. so maybe i can use this some how ?
__________________
Best use ever for C++...
http://www.planet-source-code.com/Up...3165921697.jpg
squills is offline   Reply With Quote
Old Mar 14th, 2012, 3:41 AM   #2
squills
Expert Programmer
 
squills's Avatar
 
Join Date: Feb 2009
Posts: 635
Rep Power: 6 squills is on a distinguished road
Re: counting rows in dbgrid

OK So far this is what i did, selected all the rows in the dbgrid, got the error code for each one and stored them into a tstringlist. so now i need..

1. Another stringlist but with out the duplicates
2. have stringlist2 start at first string and count how many times its in stringlist 1
3. Save stringlist 2 text to label 1 and the count to label 2
4. repeat till no more lines in stringlist2

...but how lol..
__________________
Best use ever for C++...
http://www.planet-source-code.com/Up...3165921697.jpg
squills is offline   Reply With Quote
Old Mar 14th, 2012, 4:48 AM   #3
squills
Expert Programmer
 
squills's Avatar
 
Join Date: Feb 2009
Posts: 635
Rep Power: 6 squills is on a distinguished road
Re: counting rows in dbgrid

Ahh ok i think i have this done just did it one step at a time like i said above.. but last thing i cant figure out..

in a stringlist i have something like this

bad32=5
bad33=9
bad33=2
bad33=19

were badXX is the name and of course after the = is the value.. so how do i sort the list by value? as i want the errors with the highest value on top?

cheers squills
__________________
Best use ever for C++...
http://www.planet-source-code.com/Up...3165921697.jpg
squills is offline   Reply With Quote
Old Mar 14th, 2012, 7:18 AM   #4
SalmiSoft
Freelance Programmer
 
Join Date: Sep 2011
Location: Finland & UK
Posts: 209
Rep Power: 3 SalmiSoft is on a distinguished road
Re: counting rows in dbgrid

Add this routine to your unit:
function MySorter(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result := strtoint(List.ValueFromIndex[Index2]) - strtoint(List.ValueFromIndex[Index1]);
end;
Then use the string list's CustomSort method like this:
MyCounts.CustomSort(MySorter);
(Obviously change MyCounts to the name of your string list).
SalmiSoft is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
show/hide datagridview rows by setting trackbar value bezkintos Visual Basic .NET 0 Feb 3rd, 2012 9:12 AM
Filtering ROWS with variables taken from second file CioN Sed and Awk 1 Jul 21st, 2011 11:50 PM
getting selected rows from a datagridview connected to a sql database LosIdiotosGrande C# 1 Mar 29th, 2011 4:31 AM
Problem adding/removing rows to a form. blasterstudios JavaScript and Client-Side Browser Scripting 11 May 5th, 2006 3:44 PM
How can I disable particular rows in a datagrid? HappyTomato C# 2 Aug 25th, 2005 3:48 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC