请问如何从ACCESS数据库中提取OLE型字段中的照片,然后用ASP显示在网页上?
1个回答
展开全部
//读出图片文件
<%@ 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#写的
再加点分啊 谢谢了
<%@ 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#写的
再加点分啊 谢谢了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询