c#怎么读写数据库的二进制文件?

代码: if(dr.HasRows)
{
dr.Read();
byte[] bytes = (byte[]) dr["Photo"];
MemoryStream ms =new MemoryStream(bytes);
Image image = Image.FromStream(ms);
pictureBox1.Image = image;
}

为什么总是报byte[] bytes = (byte[]) dr["Photo"];这句的错。

第1个回答  2013-05-17
(byte[]) dr["Photo"];貌似这样不能转换的吧
dr["Photo"];这个应该是一个文件名,你应该先用流把文件打开,然后转换为二进制
相似回答