怎样用ADO.NET把SQL数据库中的图像显示出来

jljkyh 2002-05-29 05:47:53
我已经用ADO把SQL数据库中的图像显示出来,但不知怎样用ADO.NET把SQL数据库中的图像显示出来,下面是其代码:
<%
dim P
dim L
L = 8192
dim conn,rs,strSql
set conn=server.CreateObject("ADODB.Connection")
conn.Open "provider=sqloledb;data source=jlijun;uid=sa;database=test"
set rs=server.CreateObject("ADODB.Recordset")
strSql = "select image from tuser where id=6"
Response.ContentType = "image/gif"
'Important!
rs.open strSql,conn,1,1
rs.movefirst

do
P = rs("image").GetChunk(L)
Response.BinaryWrite P
IF LenB(P) < L then exit do
loop
%>
...全文
103 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jljkyh 2002-05-30
  • 打赏
  • 举报
回复
有VB.NET的完整的例子代码吗?
mlab 2002-05-30
  • 打赏
  • 举报
回复
private void LoadImage()
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("",this.sqlConn);//this.sqlConn 是一个设置好的连接
cmd.CommandText = "select Map from maps where map.name ="some name";//map是Image类型
System.Data.SqlClient.SqlDataReader dreader;
this.sqlConn.Open();
dreader = cmd.ExecuteReader();
if(dreader.Read())
{
System.IO.FileStream strm=null; //我用一个临时的文件存这个图片,但好像可以直接用流显示图片,不过数据类型转换很烦,如果你解决了请告诉我。这样更安全:)
try
{
strm = new System.IO.FileStream(System.IO.Path.GetTempPath() +
"some name.tmp",System.IO.FileMode.Create,System.IO.FileAccess.ReadWrite,System.IO.FileShare.None);
byte[] barry=dreader.GetSqlBinary(0).Value;//读到的二进制流存到byte[]里
strm.Write(barry,0,barry.Length);//byte[]写到临时文件里
strm.Close();
this.theMap.Image = System.Drawing.Image.FromFile(System.IO.Path.GetTempPath() +this.Name+".tmp");//显示图片
}
catch(Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat( errorMessage, theException.Message );
errorMessage = String.Concat( errorMessage, " Line: " );
errorMessage = String.Concat( errorMessage, theException.Source );
MessageBox.Show( errorMessage, "Error" );
}
finally
{
if(strm!=null) strm.Close();
dreader.Close();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
}
dreader.Close();
this.sqlConn.Close();
}
jljkyh 2002-05-30
  • 打赏
  • 举报
回复
看了http://www.csdn.net/expert/topic/597/597408.xml?temp=.8749201
还是不明白,在ADO.NET种子表的字段有GetChunk方法吗?那位高手还可以提供源代码?
yunhi 2002-05-29
  • 打赏
  • 举报
回复
参考:http://www.csdn.net/expert/topic/597/597408.xml?temp=.8749201

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧