private void ImageOutput()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conn"];SqlCommand comm = new SqlCommand("select * from TempTable ",conn);
comm.CommandType = CommandType.Text;conn.Open();SqlDataReader dr = comm.ExecuteReader();if(dr.Read())
{
Response.Clear();
Response.ContentType=dr["imagetype"].ToString();
Response.BinaryWrite((byte[])dr["images"]);
}
dr.Close();
conn.Close();
}以上是我的.cs文件,.aspx文件中没有任何控件。请问怎么显示数据库图片啊?
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conn"];SqlCommand comm = new SqlCommand("select * from TempTable ",conn);
comm.CommandType = CommandType.Text;conn.Open();SqlDataReader dr = comm.ExecuteReader();if(dr.Read())
{
Response.Clear();
Response.ContentType=dr["imagetype"].ToString();
Response.BinaryWrite((byte[])dr["images"]);
}
dr.Close();
conn.Close();
}以上是我的.cs文件,.aspx文件中没有任何控件。请问怎么显示数据库图片啊?
解决方案 »
- vs2005提示mailmessage过时
- 谁有asp.NET 2.0(C#)导出SQL Server 2005数据库中的数据到Excel文件的代码
- html js 图像预载入........怎样去实现
- 如何指定字段名查询?
- 这是我在一个外国网站上看到的asp.net回传给服务器后会执行的一些事件,按上到下排序.谁能口语化的加下注释.
- 请问在下面的程序中如何将对象引用设置到对象的实例
- 水晶报表报错:CrystalDecisions.CrystalReports.EngineLoad crpe32.dll failed.
- 正则表达式 小刮号包含小括号 配置
- 我是.ASP初学者,以前用ASP,如何安装,除了安装必要环境的,需要安装啥必要项,主要写网页
- 印刷
- 一个网站路径中间有一串编码,每次访问都不同,怎么会回事?
- 闲着无聊,出个题,大家来玩玩!
SqlConnection cn=new SqlConnection(str);
SqlCommand cmd=new SqlCommand();
cmd.CommandText="select Cover from Books where BookGuid='"+this.Request["ImageID"]+"'";
cmd.Connection=cn;
cn.Open();
this.Response.ContentType="image/*";
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
this.Response.BinaryWrite((byte[])dr["Cover"]);
}
cn.Close();
這是asp+sql2000的,請參考。
<!--#include file="conn.asp" -->
<%
set rs1=Server.CreateObject("Adodb.Recordset")
rs1.open "select * from test where id='" & Request("id") & "'",conn,1,1
'do while not rs.eof%><%
response.ContentType="image/*"
'response.binarywrite rsTest(0).getchunk(rsTest(0).actualsize)response.binarywrite rs1("photo").getchunk(rs1("photo").actualsize)
rs1.close
'rs.movenext
'loop
'Response.ContentType="*/*"
'Response.write "OK"
%>
...
try
{
MemoryStream buf=new MemoryStream((byte[])_row[MemberData.Field_Photo]);
Image img=Image.FromStream(buf,true);
picPhoto.Image=img;
}
catch
{
}
程序如下:
//string imgid = Request.QueryString["imgid"];
string connstr = "Data Source=LENOVO-9D9FA7CF;Initial Catalog=TestDataBase;Integrated Security=True";
//Context.GetConfig("appSettings"))["connstr"];
string sql = "SELECT * FROM test where id='1';" ;
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
Response.ContentType = dr["FImage"].ToString();
Response.BinaryWrite((byte[])dr["FImage"]);
}
connection.Close();
帮看看!