请问如何从ACCESS数据库中提取OLE型字段中的照片,然后用ASP显示在网页上?

 我来答
竺彦阳aG
2006-08-08 · TA获得超过172个赞
知道答主
回答量:54
采纳率:0%
帮助的人:53.8万
展开全部
//读出图片文件
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

public void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}

private void BindGrid()
{
OleDbConnection MyCn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("ps.mdb"));
OleDbCommand MyCmd =new OleDbCommand("select * from manhua",MyCn);
MyCmd.CommandType = CommandType.Text;
try
{
MyCn.Open();
DataList1.DataSource = MyCmd.ExecuteReader(CommandBehavior.CloseConnection);
DataList1.DataBind();
}
catch(OleDbException ex)
{
Response.Write("error occured while generating data.error is " + ex.ToString());
}
}

public string FormatURL(string strArgument)
{
return("showimg.aspx?id=" + strArgument);
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<table style="WIDTH: 792px; HEIGHT: 531px" width="792">
<tbody>
<tr>
<td align="middle">
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
<table>
<tr>
<td align="center">
<font size="3" color="red"><%# DataBinder.Eval(Container.DataItem,"biaoti")%></font></td>
</tr>
<tr>
<td align="center">
<font size="2">作者:<%# DataBinder.Eval(Container.DataItem,"author")%>  来源:<%# DataBinder.Eval(Container.DataItem,"laiyuan")%></font></td>
</tr>
<tr>
<td align="center">
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "id").ToString()) %>' />
</ItemTemplate>
</td>
</tr>
<tr>
<td align="center">
<font size="2"><%# DataBinder.Eval(Container.DataItem,"content")%></font>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

//显示图片
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.IO" %>
<script runat="server">

public void Page_Load(object sender, EventArgs e)
{
try
{
string strImageID=Request.QueryString["id"];
OleDbConnection MyCn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Server.MapPath("ps.mdb"));
OleDbCommand MyCmd =new OleDbCommand("select * from manhua where id=" + strImageID,MyCn);

MyCn.Open();
OleDbDataReader dr;

dr = MyCmd.ExecuteReader(CommandBehavior.CloseConnection);
if(dr.Read())
{
Response.ContentType = dr["biaoti"].ToString();
Response.BinaryWrite((byte[])dr["img"]);
}
MyCn.Close();
}
catch(OleDbException ex)
{

}
}

</script>
<html>
<head>
</head>
<body>
<form id="Form1" runat="server">
</form>
</body>
</html>

我是用c#写的
再加点分啊 谢谢了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式