Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to add a column to datagrid that shows the number of rows ?

Status
Not open for further replies.

kirpowski

Programmer
Oct 18, 2003
5
TR
hi guys,
i am new in tek-tips and need your help. I have a form with datagrid on it and I want to use the first column of the dtagrid as a Counter which shows the row number(SiraNo is thename of the column). I have written this code (below), under the command (in dataenvironment) but it is not counting, isntead of counting it puts 1 to all of the rows...but it should go like 1..2..3..
if anyone can help i really appreciate.

thanks,
kirpowki


SELECT COUNT(*) AS SiraNo, KayitNo AS KNo, Birim,
Bolum AS Bölüm, KasaMarka AS KMarka, CPU,
SorumluP AS KullaniciP, SenetAlan AS SenediAlanP
FROM tblPC
GROUP BY KayitNo, Birim, Bolum, KasaMarka, CPU, SorumluP,
SenetAlan
ORDER BY KayitNo
 
First you need to understand what COUNT(*) does. It reports how many records have been retrieved for each set of unique values in your GROUP BY clause. You will get 1, 2, 3, ... only if the first group has 1 record, the second group has 2, etc. What it is telling you is that there is 1 record in each of the groups.

Unfortunately there is no general way to attach sequential line numbers to a recordset using SQL alone ... and line numbers are further complicated by the fact that it is possible to sort records in a recordset (hence change the line number) after you have retrieved the data from the database.
 
The easiest way i found is to retrieve all the data from your database into a temp table. Then iterate through your table, and put each line into another visible table, with a counter in the first column.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top