Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add row numbering in crystal report C#

I have started creating reports using crystal reports. I am able to show everything using dataset and sql except for the auto-row numbering.

Here's my code:

SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=Kim; initial catalog=DBO;user id=sa; password=passw0rd";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select Name as DataColumn1, Age as DataColumn2,  from tbl1";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
cnn.Close();

DataSet2 ds = new DataSet2();
dscmd.Fill(ds, "DataTable2");

CrystalReport1 objRpt = new CrystalReport1 ();
objRpt.SetDataSource(ds.Tables[0]);

CrystalReportViewer1.ReportSource = objRpt;
CrystalReportViewer1.RefreshReport();

The Result of the report is like this:

No  Name    Age
    Kim     22
    Ian     29
    Aris    27

Need to show the report like this:

No  Name    Age
1   Kim     22
2   Ian     29
3   Aris    27

Can you give me idea on how to add row number.

like image 881
Kim martin Rocero Avatar asked Aug 30 '13 05:08

Kim martin Rocero


2 Answers

  1. Create a new 'Running Total Field'
  2. Give a name for the field Like 'RowNo'
  3. Choose a field to summarize
  4. Set the 'Type of summary' to 'distinct count'
  5. In 'Evaluate' choose 'For each record'
  6. In 'Reset' choose 'Never'

    Click OK Add the field to the report. enter image description here

like image 113
Jig12 Avatar answered Sep 21 '22 11:09

Jig12


In crystal report their is option to add auto increment field,no need to fetch rownumber from database

like image 27
Sumeshk Avatar answered Sep 21 '22 11:09

Sumeshk