关于Gridview显示图片问题
我从数据库里取了两次数据,第一次取的是普通字段,第二次取的是图片如下:
//显示所有商品信息
public DataSet AllProductTest()
{
String sql = "select name as 商品名称,outprice as 商品价格,unit as 生产厂家,createdate as 生产日期,desn as 详细介绍 from product";
db = new DataBase();
return db.ExecuteAllProduct(sql);
}
//显示商品图片
public SqlDataReader PictureTest()
{
String sql = "select name as 姓名, picturedata from product";
db = new DataBase();
return db.Executepicture(sql);
}
我的读图片:
//读取图片
public void picture()
{
int bufferSize = 101;
byte[] buffer = new byte[101];
long startLocation = 0;
long returnLength;
SqlDataReader dr = new OperationLogin().PictureTest();
if (dr.HasRows)
{
while (dr.Read())
{
startLocation = 0;
string path = Server.MapPath("~") + "\\image\\" + dr.GetString(0) + ".jpg";
if (!File.Exists(path))
{
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
returnLength = dr.GetBytes(1, startLocation, buffer, 0, bufferSize);
while (returnLength == bufferSize)
{
bw.Write(buffer);
bw.Flush();
startLocation += bufferSize;
returnLength = dr.GetBytes(1, startLocation, buffer, 0, bufferSize);
}
bw.Write(buffer, 0, (int)(returnLength - 1));
bw.Flush();
}
}
dr.Close();
}
}
图片可以取到本地来,但是就是有时候有的不能显示;
我在Gridview里绑定:
<Columns>
<asp:BoundField DataField="商品名称" HeaderText="商品名称" ReadOnly="True" />
<asp:BoundField DataField="商品价格" HeaderText="商品价格" ReadOnly="True" />
<asp:BoundField DataField="生产厂家" HeaderText="生产厂家" ReadOnly="True" />
<asp:BoundField DataField="生产日期" HeaderText="生产日期" ReadOnly="True" />
<asp:BoundField DataField="详细介绍" HeaderText="详细介绍" ReadOnly="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image width="100" height="150" ID="image" src='image\<%#Eval("姓名") %>.jpg' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
可是不显示呀!
谢谢大家了!