I am trying to geneartion QR Code in Crystal Report, but it is not showing
I followed below link,
protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
{
rpt.Dispose();
rpt.Close();
loadReport();
}
}
private void loadReport()
{
SBprint.Dispose();
rpt.Close();
SqlConnection con = new SqlConnection();
con = new SqlConnection("Data Source=server1\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("spSelectOrderDetail", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@OrderNo", Request.QueryString["OID"]);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet dt = new DataSet();
da.Fill(dt);
dt.Tables["Table"].Columns.Add(new DataColumn("QRCode", typeof(byte[])));
foreach (DataRow dr in dt.Tables["Table"].Rows)
{
dr["QRCode"] = GenerateQrCode(dr["BalNo"].ToString());
}
rpt = new ReportDocument();
SBprint.RefreshReport();
rpt.Load(Server.MapPath("~/Bigbal.rpt"));
rpt.SetDataSource(dt.Tables["Table"]);
SBprint.ReportSource = rpt;
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, false, "Probale");
rpt.Close();
rpt.Dispose();
con.Close();
}
catch (Exception ex)
{
rpt.Close();
rpt.Dispose();
con.Close();
}
}
private byte[] GenerateQrCode(string qrmsg)
{
string code = qrmsg;
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
using (Bitmap bitMap = qrCode.GetGraphic(20))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
return byteImage;
}
}
}
protected void CRBigview_Unload(object sender, EventArgs e)
{
try
{
rpt.Close();
rpt.Dispose();
}
catch { }
}