Windows Forms: How to generate QRCode in RDLC Report using C#

This post shows you how to generate qr code in rdlc report using c#. You can use the qrcoder library to create qr code in c#.net windows forms application.

Drag 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.

private void Form1_Load(object sender, EventArgs e)
{
    this.reportViewer1.RefreshReport();
    this.reportViewer1.LocalReport.EnableExternalImages = true;
}

Add code to handle the Generate button click event as the following 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();
        reportData.QRCode.AddQRCodeRow(qRCodeRow);

        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Name = "ReportData";
        reportDataSource.Value = reportData.QRCode;
        reportViewer1.LocalReport.DataSources.Clear();
        reportViewer1.LocalReport.DataSources.Add(reportDataSource);
        reportViewer1.RefreshReport();
    }
}

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.

VIDEO TUTORIAL