How to Generate QR Code in RDLC Report using C#

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 a Form_Load event handler to load your rdlc report

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

Adding code to handle the button click event allows you to generate a qr code and display it in the report viewer control

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