ahmed elbarbary

ahmed elbarbary

  • 618
  • 1.6k
  • 287.5k

How to Generate QR Image to crystal report dynamically without add new

Dec 27 2024 9:15 PM

Can I add a QR image to a Crystal Report dynamically without adding a new column to the

dataset and dragging it to the report? I retrieve the URL from the database, and based on

that, I display the image from S3 in a blob field.

I need to generate the blob field dynamically in Crystal Reports without adding a new

column (e.g., QRIMG11) and dragging it to the report. My goal is to add and display the QR

image in Crystal Reports dynamically based on the database URL I retrieve, and then display

the image returned from S3 for Column QRIMG11 Without add column Manually and drag it to

crystal report .

Is this possible in Crystal Reports?

var ds = db.GET_UNIFIED_GOVS(P_LICN_CIVIL_ID, P_LICN_CENTRAL_NO);

    var P_DATA_CUR = ds.Tables["P_DATA_CUR"];

    // check dynamic qr filling 
    int numberOfQRCodes = P_DATA_CUR.Rows.Count; // Get the number of rows (QR codes)
    DataTable qrParamsTable = new DataTable(); // This will hold all QR images

    // Create columns for each QR code image
    for (int i = 0; i < numberOfQRCodes; i++)
    {
        qrParamsTable.Columns.Add($"QRIMG{i + 1}", typeof(byte[])); // Add column for each QR image
    }

    // Create a single row
    DataRow qrParamsRow = qrParamsTable.NewRow();

    // Loop through each row in the DataTable to fill the single row
    for (int i = 0; i < numberOfQRCodes; i++)
    {
        string qrObjectKey = P_DATA_CUR.Rows[i]["FILE_NAME"].ToString();

        // Get the image bytes from S3 using your existing method
        var imageBytes = new AwsFile() { objectKey = qrObjectKey }.GetImageBytesS3();

        // Set the value in the single row for the corresponding column
        qrParamsRow[$"QRIMG{i + 1}"] = imageBytes;
    }

    // Add the filled row to the DataTable
qrParamsTable.Rows.Add(qrParamsRow);
 eReg_Crystal.Rpt.RptGET_UNIFIED_GOVS_Test cr = new Rpt.RptGET_UNIFIED_GOVS_Test();
    cr.SetDataSource(P_DATA_CUR);

   cr.Database.Tables["QrParams"].SetDataSource(qrParamsTable);

 


Answers (1)