How to generate QRCode in RDLC Report using C#

By FoxLearn 7/18/2024 8:18:33 AM   20.81K
To generate a QR code in an RDLC (Report Definition Language Client-side) report using C# in a Windows Forms application, you can follow these steps.

You can use the qrcoder library to create QR code in c# Windows Forms application.

How to generate QRCode in RDLC Report

To generate a QR code in an RDLC (Report Definition Language Client-Side) report using C#, you'll typically follow these steps:

Open your Visual Studio, then create a new Windows Forms application project.

Next, Drag and drop the TextBox, Button and ReportViewer controls from the Visual Studio toolbox to your winform, then design a simple UI that allows you to enter the text, then show qr code in rdlc report using c# code as shown below.

how to create qr code in ssrs report

To add qr code in rdlc report, you need to install the QRCoder library from the Manage Nuget Packages in your visual studio. Next, Create a DataSet named ReportData, then add the QRCode table as shown below to the DataSet. Note, Image column has data type as byte array.

c# qr code

QRCoder is an open source library that helps you create qr code, then show qr code in ssrs report.

Right click on your project, then select Add->New Item->select the Report (*.rdlc). Drag the Image control from the report toolbox to your report, then add the DataSource of report to the ReportData.

Now, Open your form designer, then select the ReportViewer control. Next, select your report from the report combobox in ReportViewer control.

Double click on your form, then add code to handle the form load event as shown below.

// c# to rdlc qrcoder
private void Form1_Load(object sender, EventArgs e)
    this.reportViewer1.LocalReport.EnableExternalImages = true;

Add code to handle the Generate button click event as the following code.

// c# generate qr code
private void btnGenerate_Click(object sender, EventArgs e)
    QRCoder.QRCodeGenerator qRCodeGenerator = new QRCoder.QRCodeGenerator();
    QRCoder.QRCodeData qRCodeData = qRCodeGenerator.CreateQrCode(textBox1.Text, QRCoder.QRCodeGenerator.ECCLevel.Q);
    QRCoder.QRCode qRCode = new QRCoder.QRCode(qRCodeData);
    Bitmap bmp = qRCode.GetGraphic(5);
    using (MemoryStream ms = new MemoryStream())
        bmp.Save(ms, ImageFormat.Bmp);
        ReportData reportData = new ReportData();
        ReportData.QRCodeRow qRCodeRow = reportData.QRCode.NewQRCodeRow();
        qRCodeRow.Image = ms.ToArray();

        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Name = "ReportData";
        reportDataSource.Value = reportData.QRCode;

To show qr code or barcode in rdlc report, you should save the qr code image to MemoryStream, then convert the MemoryStream to byte array and add the byte array to the DataRow.

Finally, Set the DataSource to ReportViewer control, and don't forget clear the DataSource before adding.