本文介绍了如何将字节数组分配到数据行列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为datarow列分配一个字节数组...当我分配如下后,该值显示为System.Byte [] 而不是实际的字节数组...
Hi,
I want to assign a byte array to datarow column...When i assigned like following the value is showing as "System.Byte[]" instead of actual byte array...
row1 = dsDetail.Tables["table"].NewRow();
dsDetail.Tables["table"].Columns["logo"].DataType=System.Type.GetType("System.Byte[]");
byte[] P = ImageToByteArray(a);
row1["logo"] = P;
//function used to get byte array
public byte[] ImageToByteArray(string imagepath)
{
FileStream fs;
fs = new FileStream(imagepath, FileMode.Open, FileAccess.Read);
//a byte array to read the image
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
return picbyte;
}
推荐答案
DataTable dt = new DataTable();
dt.Columns.Add("imageByte", typeof(byte[]));
byte[] imageByte = null;
imageByte=ImageToByteArray(Server.MapPath(@"\images\yourImage.png"));
DataRow drNew = dt.NewRow();
drNew["imageByte"] = imageByte;
dt.Rows.Add(drNew);
谢谢
Rashed ::孟加拉国
thanks
Rashed::Bangladesh
这篇关于如何将字节数组分配到数据行列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!