how to generate serial number in Crystal Report using c#
  • I want to generate serial number in crystal report how it is possible. I have a customer report and there is a cond. when I print acustomer receipt and whenever I again run the application the receipt serial number start from last print number. For Example print 5 customer receipt from 1 to 5 then again run application and start printing receipt serial number start from 6 and so on not from 1. How it is possible in CR using C#......
  • 9 Comments sorted by
  • hi @ahsankamal
    you can use running total for this kind of work follow this steps.

    goto Field Explorer
    right click on RunningTotalField
    select New
    then in Evaluate section select For Each Record.

    or you can also assign it through SQL query see thi link for query http://codingresolved.com/discussion/527/serial-number-in-sql/p1
  • as your requirement you can make one table and on every print button click you have to generate new number from max query then save it in table then call it max number in your report or pass as parameter field after calling from database.
  • ithacker and sajiddesigner i want to generate serial if i print page 1 and again run the application the page number start from page2 if i use runnig total every page number start from 1...
  • Waqas how it is possible can u give some code example...
  • Actually the report is based on 2categories if category1 customer print in 2pages and category2 customer record print in 1page there is total 3pages,  how to record the pages in database for suture reference...
     
  • Kindly download attached code and make one table in Database.

    USE [dbTest]

    CREATE TABLE [dbo].[tblSequence](
    [SerialNo] [int] NOT NULL
    ) ON [PRIMARY]
    WindowsFormsApplication2.zip
    59K
  • Waqas file is not downloadable...
  • kindly click on this link http://codingresolved.com/uploads/FileUpload/46/3a30ff29afcf246a503a94512dddab.zip

    by the way code is this.
    i have make one parameter field in crystal report with name of "SerialNo"


    private void button1_Click(object sender, EventArgs e)
    {
    SqlConnection objCon = new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=dbTest;Integrated Security=True");

    SqlCommand objCmd = new SqlCommand("Select IsNull(Max(SerialNo),0) +1 SerialNo from tblSequence ", objCon);

    SqlDataAdapter objDA = new SqlDataAdapter(objCmd);

    objDA.SelectCommand.CommandText = objCmd.CommandText.ToString();
    DataTable dt = new DataTable();

    objDA.Fill(dt);

    string SerialNo = dt.Rows[0][0].ToString();
    string Query="Insert Into tblSequence Values(@SerialNo)";
    Query = Query.Replace("@SerialNo", SerialNo);

    objCmd = new SqlCommand(Query , objCon);

    objDA = new SqlDataAdapter(objCmd);

    objDA.SelectCommand.CommandText = objCmd.CommandText.ToString();
    objDA.Fill(dt);

    objCmd = new SqlCommand("Select IsNull(Max(SerialNo),0) SerialNo from tblSequence ", objCon);

    objDA = new SqlDataAdapter(objCmd);

    objDA.SelectCommand.CommandText = objCmd.CommandText.ToString();
    dt = new DataTable();

    objDA.Fill(dt);

    SerialNo = dt.Rows[0][0].ToString();
    textBox1.Text = (Convert.ToDecimal(dt.Rows[0][0].ToString())).ToString("C");

    CrystalReport1 rpt = new CrystalReport1();
    rpt.SetParameterValue("SerialNo", SerialNo);
    crystalReportViewer1.ReportSource = rpt;



    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Top Posters Weekly

Optimum Creative