Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to display image in crystal report. For that
I have to asign image in dataset, so i have use typeof(System.Byte[]).
this will work fine in 32 bit system, but not working in 64 bit system.

Below is code i have use...
so what is solution for 64 bit system to work...?

What I have tried:

public static ReportDocument SetImage(ReportDocument sReport, int ReportIndex, string ReportName, string ImagePath)
{
try
{
FileStream FilStr = new FileStream(ImagePath, FileMode.Open);
BinaryReader BinRed = new BinaryReader(FilStr);
DataSet DsImages = new DataSet();
DataTable ImageTable = new DataTable("img");
//ImageTable.Columns.Add(new DataColumn("path", typeof(string)));
ImageTable.Columns.Add(new DataColumn("img", typeof(System.Byte[])));
DsImages.Tables.Add(ImageTable);
DataRow dr = DsImages.Tables["img"].NewRow();
//dr["path"] = ImagePath;
//Convert.ToBase64String(imgBytes)
dr["img"] = Convert.FromBase64String(Convert.ToBase64String(BinRed.ReadBytes((int)BinRed.BaseStream.Length)));
DsImages.Tables["img"].Rows.Add(dr);
FilStr.Close();
BinRed.Close();
//sReport.Database.Tables[1].SetDataSource(DsImages.Tables["images"]);

sReport.Subreports[ReportIndex].SetDataSource(DsImages.Tables[0]);

return sReport;
}
catch (Exception Ex)
{
MessageBox.Show("Error At : Program.SetImage() \n\n" + Ex.Message);

return sReport;
}
}
Posted
Updated 3-Jun-17 1:46am
Comments
Richard MacCutchan 3-Jun-17 7:33am    
Why are you converting the bytes to a string just to convert them back to bytes? That is bound to cause problems. Just read the bytes from the original image file and do not mess with them.

1 solution

If you need bytes in your table, then just do it:
public static ReportDocument SetImage(ReportDocument sReport, int ReportIndex, string ReportName, string ImagePath)
    {
    try
        {
        DataTable imageTable = new DataTable("img");
        imageTable.Columns.Add(new DataColumn("img", typeof(System.Byte[])));
        DataRow dr = imageTable.NewRow();
        dr["img"] = File.ReadAllByes(ImagePath);
        imageTable.Rows.Add(dr);
        sReport.Subreports[ReportIndex].SetDataSource(imageTable); 
        return sReport;
        }
    catch (Exception Ex)
        {
        MessageBox.Show("Error At : Program.SetImage() \n\n" + Ex.Message);
        return sReport;
        }
    }
 
Share this answer
 
v2
Comments
Member 9720862 3-Jun-17 8:02am    
yes , i know this.. but this code will work only for 32 bit, but not working in 64 bit system...
OriginalGriff 3-Jun-17 8:11am    
That's not the fault of that code then- it's something else in your system. Bytes are bytes regardless of the system size, they are fixed a eight bits. Most likely it's a 32 bit DLL you are accessing: you can't "switch" sizes in midd app, that doesn't work.

What error do you get?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900