Click here to Skip to main content
15,914,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

Below is the code by which i am printing data from dataset

C#
sr.WriteLine(i.ToString() + Strings.Space(3 - Strings.Len(i.ToString())) + String.Format("{0,-6:dd MMM yyyy}", ds.Tables[0].Rows[i][1]) + Strings.Space(13 - Strings.Len(String.Format("{0,-6:dd MMM yyyy}", ds.Tables[0].Rows[i][1]))) + Strings.Mid(per.ToString(), 1, 25) + Strings.Space(((35 - Strings.Mid(per.ToString(), 1, 25).Length))) + ds.Tables[0].Rows[i][3].ToString() + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][3].ToString())) + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][5].ToString())) + ds.Tables[0].Rows[i][5].ToString() + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][6].ToString())) + ds.Tables[0].Rows[i][6].ToString() + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][7].ToString())) + ds.Tables[0].Rows[i][7].ToString());


e.g. Records are coming like this

Date              Particulars                 ChequeNo        Withdrawals  Deposite    Balance
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
01 Nov 2011  By Cash                            0                 0.0000    210.0000      210.00
02 Nov 2011  By Cash                            0                 0.0000  15000.0000    15210.00
02 Nov 2011  To TRF TD/RD/34 DAMLE AMO          0              6000.0000      0.0000     9210.00
15 Nov 2011  By KTH ABB Cash BY CASH D          0                 0.0000   2813.0000    12023.00


Now i want to add serial number before the date.
like
1
2
3...
and suppose first time it printed 7 lines then next time the serial number should start from 8.
Please tell me how to do this.
Posted
Comments
DamithSL 5-Jul-14 0:27am    
what you mean by next time?
can't you use integer value and increment it for each line?
PIEBALDconsult 5-Jul-14 0:33am    
If SQL server, look into the ROW_NUMBER function.
Atyant Srivastava 5-Jul-14 0:40am    
Use integer value and increment it for each line, once done store the last value and next time get that value to start with. You need to store the last generated value.

set indentity(1,1) on id which having with primary key
 
Share this answer
 
The easiest way is to add another column to the query which is reading the rows. You can use the function ROW_NUMBER().

See one example - Insert row number as a column in datatable/dataset[^]
 
Share this answer
 
if u insert next data then it will be start from previous entry
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900