Click here to Skip to main content
15,886,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
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


C#
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

C#
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

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