我写了一些代码用来显示商品信息
<asp:DataList id="DataList1" runat="server" RepeatColumns="2" Width="240px" RepeatDirection="Horizontal" Height="155">
<ItemTemplate>
<TABLE style="HEIGHT: 155px" cellSpacing="0" cellPadding="0" width="240" border="0">
<TR>
<TD vAlign="top" width="90" height="92">
<A href='GoodsDetails.aspx?GoodsID=<%# DataBinder.Eval(Container.DataItem, "GoodsID") %>'>
//该处显示图像?????????
</A>
</TD>
<TD vAlign="top" width="144">
<A title=查看详细资料 href='GoodsDetails.aspx?GoodsID=<%# DataBinder.Eval(Container.DataItem, "GoodsID") %>'>
<%# DataBinder.Eval(Container.DataItem,"GoodsName")%>
</A>
<BR> <!--原价--> 原价:<del>¥<%# DataBinder.Eval(Container.DataItem,"OriginalPrice")%></del>
<br>
现价:¥<%# DataBinder.Eval(Container.DataItem,"SalePrice")%>
</TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:DataList>
请问怎样从数据库中取得,存成二进制的了,求代码
<asp:DataList id="DataList1" runat="server" RepeatColumns="2" Width="240px" RepeatDirection="Horizontal" Height="155">
<ItemTemplate>
<TABLE style="HEIGHT: 155px" cellSpacing="0" cellPadding="0" width="240" border="0">
<TR>
<TD vAlign="top" width="90" height="92">
<A href='GoodsDetails.aspx?GoodsID=<%# DataBinder.Eval(Container.DataItem, "GoodsID") %>'>
//该处显示图像?????????
</A>
</TD>
<TD vAlign="top" width="144">
<A title=查看详细资料 href='GoodsDetails.aspx?GoodsID=<%# DataBinder.Eval(Container.DataItem, "GoodsID") %>'>
<%# DataBinder.Eval(Container.DataItem,"GoodsName")%>
</A>
<BR> <!--原价--> 原价:<del>¥<%# DataBinder.Eval(Container.DataItem,"OriginalPrice")%></del>
<br>
现价:¥<%# DataBinder.Eval(Container.DataItem,"SalePrice")%>
</TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:DataList>
请问怎样从数据库中取得,存成二进制的了,求代码
解决方案 »
- 初学jquery向各位请教
- asp.net防盗链如何做?
- 一个很烦人的存储过程!!求高手
- asp.net中在datagrid里直接对记录修改,删除。望高手指点。
- 请问如何格式化日期?
- 超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
- .net打开数据库正常,操作就出错,跪求大神!
- 数据库输入字符串的格式不正确,如何解决!!
- 提问:JSP中有Bean来封装应用逻辑和类库,ASP.Net中如何来实现呢?
- 一个错误很古怪,在98\xp下没有,2000下却有(内详)
- 问一个在vs2005中压缩文件的问题??孟子E章,思归老大和各位大侠都进来看看
- 使用 Cookies 需要在Web.config里做什么修改吗?
if(myFile.ContentLength != 0)
{
try
{
System.Web.HttpPostedFile myFile = this.Request.Files[0];
// string tmpFileName = myFile.FileName;
// string myFileName = tmpFileName.Substring(tmpFileName.LastIndexOf("."));
// string myFileMimeType = myFile.ContentType();
// myFile.SaveAs(this.Server.MapPath("../" + myFileName)); //读取到数组里面
System.IO.Stream mystream = myFile.InputStream;
byte[] Buffer = new byte[myFile.ContentLength];
mystream.Read(Buffer,0,myFile.ContentLength); //打开数据库
OracleConnection cn = new OracleConnection(ConfigurationSettings.AppSettings["sysDSN"]);
cn.Open(); //用参数方式写入数据库
OracleCommand myComm = cn.CreateCommand();
string sql = "insert into tmp(tmp_id,tmp_blob) values(tmp_seq.nextval,:tmp_blob)";
myComm.CommandText = sql;
myComm.Parameters.Add(":tmp_blob",OracleType.Blob,Buffer.Length).Value = Buffer;
myComm.ExecuteNonQuery();
}
catch
{
//此处可加错误显示
}
finally
{
cn.Close();
}
}
在页面中,放一个Image控件,在后台指定它的链接地址如下:
----------------------------------------------------------------------
//为方便,写一个固定ID号tmp_id=103
this.Image1.ImageUrl = "showimg.aspx?tmp_id=103" ;
下面是显示图片的页面showimg.aspx后台代码,该页面不需要放任何东西.
--------------------------------------------------------------------
//创建数据库连接
OracleConnection myConnection = new OracleConnection(ConfigurationSettings.AppSettings["sysDSN"]);
myConnection.Open();//打开数据库
OracleCommand myCommand = myConnection.CreateCommand();
string sql = "select tmp_blob from tmp where tmp_id = 103";
myCommand.CommandText = sql;
OracleDataReader myRead = myCommand.ExecuteReader();//开始读取
myRead.Read();
//这个方法更直接
Byte[] Buffer = (Byte[])myRead[0];
//OracleLob myLob = myRead.GetOracleLob(0);
//长度是long,转为int32
//int myLength = Convert.ToInt32(myLob.Length);
//Byte[] Buffer = new byte[myLength];
//myLob.Read(Buffer,0,myLength);//输出
this.Response.Clear();
//输出mime类型,根据上传的文件取到的mimetype,是什么我忘记了,自己写上,不过不写也没有关系.
this.Response.ContentType = "";
this.Response.BinaryWrite(Buffer);
this.Response.End();
public void ResponseImages(string ID)
{
string Cmd_String="Select CtPicType, CtPicContent from Info_content Where CtID=@ID";
SqlDataReader myDataReader;
try
{
SqlParameter[] arParams = new SqlParameter[1];
arParams[0] = new SqlParameter("@ID", ID);
myDataReader = SqlHelper.ExecuteReader(Conn_String, CommandType.Text,Cmd_String,arParams);
if(myDataReader.Read())
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = myDataReader["CtPicType"].ToString();
System.Web.HttpContext.Current.Response.BinaryWrite((byte[])myDataReader["CtPicContent"]);
}
}
catch
{
//出错了.
}
finally
{
if(Conn_String.State==ConnectionState.Open)
{
Conn_String.Close();
}
//myDataReader.Close();
}
System.Web.HttpContext.Current.Response.End();
}
#endregion