This tutorial will show you how to generate qr code in RDLC Report using C#.NET Windows Forms Application
To play the demo, you need to create a new rdlc report, then install qrcoder from Manage Nuget Packages to your project
or you can run nuget command PM> Install-Package QRCoder
As you know, QRCoder is an open source library that helps you generate qr code, bar code
From your report tool box, drag an image control into your report, then set the datasource to your image control
=First(Fields!Image.Value, "ReportData")
You can design a simple UI allows you to enter a text, then generate and display the qr code to your rdlc report
Adding code to handle the button click event allows you to generate a qr code and display it in the report viewer control
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DevApp
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void Form6_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
this.reportViewer1.LocalReport.EnableExternalImages = true;
}
private void button1_Click(object sender, EventArgs e)
{
QRCoder.QRCodeGenerator generator = new QRCoder.QRCodeGenerator();
QRCoder.QRCodeData data = generator.CreateQrCode(textBox1.Text, QRCoder.QRCodeGenerator.ECCLevel.Q);
QRCoder.QRCode qR = new QRCoder.QRCode(data);
Bitmap bmp = qR.GetGraphic(7);
using (MemoryStream ms = new MemoryStream())
{
bmp.Save(ms, ImageFormat.Bmp);
ReportData reportData = new ReportData();
ReportData.QRCodeRow row = reportData.QRCode.NewQRCodeRow();
row.Image = ms.ToArray();
reportData.QRCode.AddQRCodeRow(row);
ReportDataSource reportDataSource = new ReportDataSource();
// Must match the DataSource in the RDLC
reportDataSource.Name = "ReportData";
reportDataSource.Value = reportData.QRCode;
reportViewer1.LocalReport.DataSources.Add(reportDataSource);
reportViewer1.RefreshReport();
}
}
}
}
You need to generate qr code to an image, then convert the image to byte array. Finally, add the byte array to your data source
I hope so you can solve the problem add a byte image to RDLC report