日期:2014-05-17 浏览次数:20461 次
public DataRow GetBookDetail(int BookId) { string strsql; DataSet myDs; try { strsql="select BookType.Name as BookTypeName,book.id,book.name,author,price,type,publisher,Description,translator,discount,hits,status,sales,image=case when(not Cover is null) then ' <img src=Readimage.aspx?id='+cast(book.id as varchar(10))+' Border=1 width=80 height=120>' else ' <img src=img/pic.jpg border=1 width=80 height=120>' end from book join BookType on book.type=booktype.id where Book.id="+BookId; myDs=ExecuteSql4Ds(strsql); return myDs.Tables[0].Rows[0]; } catch(System.Data.SqlClient.SqlException er) { throw new Exception(er.Message); } } //读取二进制流的Readimage.aspx页面代码: DataView myDv; int id=int.Parse(Request.QueryString["id"].Trim()); SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=bookshop;Integrated Security=True"); string cmdText = "select cover from book where id="+id+""; con.Open(); SqlDataAdapter sda = new SqlDataAdapter(cmdText,con); DataSet ds = new DataSet("ds"); sda.Fill(ds); myDv = ds.Tables[0].DefaultView; con.Close(); try { Response.ContentType = "image/*"; Response.BinaryWrite((byte[])myDv[0]["Cover"]); } catch { Response.Write("/img/pic.jpg"); }