hi i have web application in which i need to store image into one of column of datatble but i am getting error when doing this.Here is my code i tried for this.
DataTable dt = new DataTable();
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(byte[]));
//dt.Columns.Add("logoname", typeof(System.Byte[]));
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());
}
Getting error
Type of value has a mismatch with column typeCouldn't store in logoname Column. Expected type is Byte[].
on this line
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());
This is functon i call to get image
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;
}
what to do? need help.