Click here to Skip to main content
11,634,631 members (74,207 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I am using vs2008 to print records in through Crystal Reports.
But at the time of display it is displaying all the records, from the first record.

but I want to print depending on a query.

but my code is not executing or working.
Please help.

ReportDocument cryRpt = new ReportDocument();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables;
        string connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
        SqlConnection con = new SqlConnection(connStr);
        con.Open();
        SqlDataAdapter da3 = new SqlDataAdapter("select * from Details where slno='" + TextBox1.Text + "'", con);
        DataSet ds3 = new DataSet();
        da3.Fill(ds3, "Details");
 
        cryRpt.Load(HttpContext.Current.Server.MapPath("rptFlexiReceipt.rpt"));
        cryRpt.SetDataSource(ds3);
        crConnectionInfo.ServerName = "123.123.123.123";
        crConnectionInfo.DatabaseName = "database1";
        crConnectionInfo.UserID = "user1";
        crConnectionInfo.Password = "password1";
 
        CrTables = cryRpt.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }
 
        CrystalReportViewer1.ReportSource = cryRpt;
        System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
        int i;
        int rawKind = 0;
        for (i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++)
        {
            if (printDoc.PrinterSettings.PaperSizes[i].PaperName == "10x6")
            {
                rawKind = (int)GetField(printDoc.PrinterSettings.PaperSizes[i], "kind");
            }
        }
        cryRpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
        // cryRpt.PrintToPrinter(1, true, 0, 0);
        cryRpt.SetDataSource(ds3);
        CrystalReportViewer1.RefreshReport();
 
please notice the line no 9
the query I want to execute.
Posted 31-Jan-13 11:38am
Comments
onurag19 at 1-Feb-13 3:19am
   
Have you mentioned textbox1 in crystal report?
(Sarkar Dada).And what error you are getting ?
Sourav Sarkar-SS2 at 2-Feb-13 10:34am
   
There is no Error but my problem is all the records are appearing. where I want want only one record specified in the Textbox1.

how to specify textbox in CrystalReport. I didn't got u.
vinodkumarnie at 1-Feb-13 5:25am
   
paste the error what u face...?
Sourav Sarkar-SS2 at 2-Feb-13 4:16am
   
There is no Error but my problem is all the records are appearing.
where I want want only one record specified in the Textbox1.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

ReportDocument cryRpt = new ReportDocument();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables;
        string connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
        SqlConnection con = new SqlConnection(connStr);
        con.Open();
        SqlDataAdapter da3 = new SqlDataAdapter("select * from FlexiDetails where slno='" + TextBox1.Text + "'", con);
        DataSet ds3 = new DataSet();
        da3.Fill(ds3, "finalbill");
 
        cryRpt.Load(HttpContext.Current.Server.MapPath("rptFlexiReceipt.rpt"));
        cryRpt.SetDataSource(ds3.Tables[0]);
        crConnectionInfo.ServerName = "208.91.198.196";
        crConnectionInfo.DatabaseName = "sevamx7z_SEVADBES";
        crConnectionInfo.UserID = "seva_root";
        crConnectionInfo.Password = "seva@321";
       
 
        CrTables = cryRpt.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }
 
        CrystalReportViewer1.ReportSource = cryRpt;
        System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
        int i;
        int rawKind = 0;
        for (i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++)
        {
            if (printDoc.PrinterSettings.PaperSizes[i].PaperName == "10x6")
            {
                rawKind = (int)GetField(printDoc.PrinterSettings.PaperSizes[i], "kind");
            }
        }
        //cryRpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
        // cryRpt.PrintToPrinter(1, true, 0, 0);
        cryRpt.SetDataSource(ds3);
        CrystalReportViewer1.RefreshReport();




NOTICE LINE
cryRpt.SetDataSource(ds3.Tables[0]);
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 8,736
1 Sergey Alexandrovich Kryukov 8,359
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205


Advertise | Privacy | Mobile
Web04 | 2.8.150728.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100