Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# image CrystalReports
i have web application in which i need to create crystal report.so that i have dataset named "dsHeader" which is assigned to crystal report as datasource.In this report i need to show image.
I get data from database and get stored in one of table nad then merge this datable with `dsheader` below is the code i tried
 
SalesHeader dsHeader = new SalesHeader();
            
            DataTable dt=new DataTable();
            
            dt.Columns.Add("ShipAddress", typeof(System.String));
            dt.Columns.Add("Companyname", typeof(System.String));
            dt.Columns.Add("Companyaddress", typeof(System.String));
            dt.Columns.Add("CompEmail", typeof(System.String));
            dt.Columns.Add("CompTelephone", typeof(System.String));
            dt.Columns.Add("logoname", typeof(System.Byte[]));
            
            Dataset imageDataSet=Getdata();//retrieve data from database
              for (int rowNumber = 0; rowNumber < imageDataSet.Tables[0].Rows.Count; rowNumber++)
                        {
                          
     imageDataSet.Tables[0].Rows[rowNumber]["logoname"] = GetByteArray("abc.jpg");
    
    
        dt.Rows.Add(imageDataSet.Tables[0].Rows[rowNumber][0].ToString(), imageDataSet.Tables[0].Rows[rowNumber][1].ToString(), imageDataSet.Tables[0].Rows[rowNumber][2].ToString(), imageDataSet.Tables[0].Rows[rowNumber][3].ToString(), imageDataSet.Tables[0].Rows[rowNumber][4].ToString(), imageDataSet.Tables[0].Rows[rowNumber][5] as System.Byte[]);
                        }
    
    dsHeader.Tables[0].Merge(dt,true, MissingSchemaAction.Ignore);
 

On this line
 
`dsHeader.Tables[0].Merge(dt,true, MissingSchemaAction.Ignore);`
 
i am getting this error:
 Type of value has a mismatch with column typeCouldn't store System.Byte[]> in logoname Column.  Expected type is Byte[].
 
this function returns image with byte aaray
private byte[] GetByteArray(String strFileName)
            {
                System.IO.FileStream fs = new System.IO.FileStream(strFileName, System.IO.FileMode.Open);
                // initialise the binary reader from file streamobject
                System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
                // define the byte array of filelength
    
                byte[] imgbyte = new byte[fs.Length + 1];
                // read the bytes from the binary reader
    
                imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
                // add the image in bytearray
    
                br.Close();
                // close the binary reader
    
                fs.Close();
                // close the file stream
                return imgbyte;
            }
 
The "logoname" field in dsHeader dataset is of System.Byte[] type.
please Help me for this.
Posted 31-Oct-12 23:00pm

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 1 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100