A StartDocPrinter call was not issued with c# code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
i am using c# and crystal report . i want to print crystal report with button click event its giving me this error , A StartDocPrinter call was not issued.
i am using this code to search record i crystal report and to print , it not even showing popup for print .
<pre class="prettyprint protected void Button2_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();

string query;
try
{
//string q = Request.QueryString["q"];
con.Open();
query = "select * from Transactions where idcount=" + TextBox1.Text + "";
cmd = new SqlCommand(query, con);
da = new SqlDataAdapter(cmd);
dt.Clear();
da.Fill(dt);
if (dt.Rows.Count > 0)
{

ReportDocument Report = new ReportDocument();
Report.Load(Server.MapPath("~/CrystalReport.rpt"));
Report.SetDataSource(dt);
query = "select * from Transactions where idcount =" + TextBox1.Text + "";
cmd = new SqlCommand(query, con);
da = new SqlDataAdapter(cmd);
dt1.Clear();
da.Fill(dt1);
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
Report.SetDatabaseLogon("sa", "123456789", @"TRAINING-ROOM-8", "newMreport");
CrystalReportViewer1.ReportSource = Report;
CrystalReportViewer1.ReportSource = Report;
CrystalReportViewer1.DataBind();
CrTables = Report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

Report.Refresh();
Report.PrintToPrinter(1, true, 1, 1 );<-- error }
}
catch
{
Response.Write("Please enter id");
}
}[/code]
<br/>
<
New born in developing

View the full article
 
Back
Top