1个回答
展开全部
要显示图片的页面设置
<asp:datalist id="MyList" repeatcolumns="2" borderwidth="0" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<img width=40 height=40 src='<%# DataBinder.Eval(Container.DataItem, "ImgId", "Img.aspx?id={0}")%>'>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
后台代码
OleDbConnection objConn = new OleDbConnection();
objConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Data.mdb");
objConn.Open();
OleDbCommand objCmd = new OleDbCommand("select * from tbl_Image", objConn);
OleDbDataAdapter da = new OleDbDataAdapter(objCmd);
DataSet ds = new DataSet();
da.Fill(ds, "aa");
MyList.DataSource = ds.Tables["aa"];
MyList.DataBind();
objConn.Close();
img.aspx页面代码
int id = int.Parse(Request["id"].ToString());
OleDbConnection objConn = new OleDbConnection();
objConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Data.mdb");
objConn.Open();
OleDbCommand objCmd = new OleDbCommand("select top 1 Image from tbl_Image where ImgId=@id order by ImgId desc",objConn);
objCmd.Parameters.Add("@id", OleDbType.Integer);
objCmd.Parameters["@id"].Value = id;
OleDbDataReader objDr = objCmd.ExecuteReader();
while(objDr.Read())
{
Response.BinaryWrite((byte[])objDr["Image"]);
}
objDr.Close();
objConn.Close();
<asp:datalist id="MyList" repeatcolumns="2" borderwidth="0" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<img width=40 height=40 src='<%# DataBinder.Eval(Container.DataItem, "ImgId", "Img.aspx?id={0}")%>'>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
后台代码
OleDbConnection objConn = new OleDbConnection();
objConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Data.mdb");
objConn.Open();
OleDbCommand objCmd = new OleDbCommand("select * from tbl_Image", objConn);
OleDbDataAdapter da = new OleDbDataAdapter(objCmd);
DataSet ds = new DataSet();
da.Fill(ds, "aa");
MyList.DataSource = ds.Tables["aa"];
MyList.DataBind();
objConn.Close();
img.aspx页面代码
int id = int.Parse(Request["id"].ToString());
OleDbConnection objConn = new OleDbConnection();
objConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Data.mdb");
objConn.Open();
OleDbCommand objCmd = new OleDbCommand("select top 1 Image from tbl_Image where ImgId=@id order by ImgId desc",objConn);
objCmd.Parameters.Add("@id", OleDbType.Integer);
objCmd.Parameters["@id"].Value = id;
OleDbDataReader objDr = objCmd.ExecuteReader();
while(objDr.Read())
{
Response.BinaryWrite((byte[])objDr["Image"]);
}
objDr.Close();
objConn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询