How to add line numbering in C # crystal report

I started creating reports using crystal reports . I can show everything using dataset and sql , except for auto-row numbering .

Here is 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 as follows:

 No Name Age Kim 22 Ian 29 Aris 27 

You need to show the report as follows:

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

Can you please let me know how to add line number.

+4
source share
6 answers
  • Create a new "Running Total Field".
  • Name the Like field 'RowNo'
  • Select a field to summarize.
  • Set "Bulletin Type" to "Different Account"
  • In the "Rate" section, select "For each entry."
  • In 'Reset, select' Never '

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

+2
source

Creating a special section 'RecordNumber' would be the easiest and easiest way to achieve it. The Record Number field is used to indicate each record printed in the Details section of your report.

+1
source

Auto Sequential Numbering in Crystal Report

  • Open Crystal Report
  • Field Explorer, right-click "Run All Fieids" - New

  • Configuration.

    3.1 Select a field to install (select a field to summarize)

    3.2 Press to select Custom Field Values

    3.3 Select “Bulletin Type” to set (“Bulletin Type” to “Great Score”)

    3.4 Set "Evaluate" for each entry

    3.5 Set "Reset" (set to "never")

    3.6 Click OK.

  • Then add a message field

    enter image description here

0
source

Use datatable and take DS.tables [0] .rows.count and take the score inside and which increases with each iteration of the loop.

  DataTable tab_lvl = new DataTable(); tab_lvl.Columns.Add(new DataColumn("NO", typeof(string))); tab_lvl.Columns.Add(new DataColumn("Name", typeof(string))); tab_lvl.Columns.Add(new DataColumn("AGE", typeof(string))); tab_lvl.Columns.Add(newDataColumn("Allot_Asset_Code",typeof(string))); int count; for(int i=0;i<ds.Tables[0].Rows.Count;i++) { count++; DataRow dr = tab_lvl.NewRow(); dr["NO"] = count; dr["NAME"] = ds.Tables[0].Rows[i]["COLname/number"]; dr["AGE"] = ds.Tables[0].Rows[i]["COLname/number"]; } //bind the datatable to the report objRpt.SetDataSource(tab_lvl); 
-one
source

In the report on crystals, it is possible to add an automatic increment field, there is no need to extract rowan from the database

-one
source

You can change the selection request to

 select ROW_NUMBER() OVER(ORDER BY Age) as No, Name, Age from tbl1 

which will lead to the expected result.

-one
source

Source: https://habr.com/ru/post/1499734/


All Articles