• 网站首页
  • 涉税提问
  • 财税法规
  • 税收筹划
  • 优惠政策
  • 案例解析
  • 培训中心
  • 财富工具
  • 房产专题
  • 会计范文
中财税帮助

去向导航

  • 常见问题
  • 费用核算
  • 负债核算
  • 会计报表
  • 利润核算
  • 收入核算
  • 外汇核算
  • 资本核算
  • 资产核算
  • 更多...

常用分类

  • 浏览器
  • Windows
  • 音乐/电影
  • 网站开发
  • 游戏
  • 办公自动化

中财税帮助系统

2008-10-7

欢迎您登陆并使用中国财税咨询中心为您免费提供的资料,交流,学习为一体的平台!

如果您在使用中遇到什么问题,请您不要吝啬,一定要写信给我们!!

Email:Shellapi@126.com 期待您的来信,或指导批语!

帮助内难免有收集的资料,如果侵犯了您的仅力,请您来信告知,我们马上删除或更新处理!

文章搜索--请输入关键词:

在Asp.Net中从sqlserver检索(retrieve)图片

更多2008-10-7 日更新内容!
    介绍:

    这篇文章是我写的"如何把图片存入sqlServer中"的后续。我建议你在读这篇文章之前先看看那篇。

    和存储图片相比,读取图片就要简单多了。输出一副图片我们要做的就是使用Response对象的BinaryWrite方法。

    同时设置图片的格式。在这篇文章中,我们将讨论如何从SqlServer中检索图片。

    并将学习以下几个方面的知识.

    ·如何设置图片的格式?

    ·如何使用BinaryWrite方法。



    我们已经在Person表中存储了数据,那么我们就写些代码来从表中读取数据。

    下面的代码检索了所有的值从Person表中。



    从sqlserver中读取图片的代码.

    Public Sub Page_Load(sender As Object, e As EventArgs)

    Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

    Dim myCommand As New SqlCommand("Select * from Person", myConnection)

    Try

    myConnection.Open()

    Dim myDataReader as SqlDataReader

    myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)



    Do While (myDataReader.Read())

    Response.ContentType = myDataReader.Item("PersonImageType")

    Response.BinaryWrite(myDataReader.Item("PersonImage"))

    Loop



    myConnection.Close()

    Response.Write("Person info successfully retrieved!")

    Catch SQLexc As SqlException

    Response.Write("Read Failed : " & SQLexc.ToString())

    End Try

    End Sub



    看看他是怎么工作的?

    上面的例子很简单。我们所作的就是执行一个sql语句,再循环读取所有的记录(looping through all the records).

    在显示图片之前,我们先设置了图片的contentType,然后我们使用BinaryWrite方法把图片输出到浏览器。



    源代码:

    /// retriving.aspx



    <%@ Page Language="vb" %>

    <%@ Import Namespace="System.Data" %>

    <%@ Import Namespace="System.Data.SqlClient" %>

    <HTML>

    <HEAD>

    <title>Retrieving Image from the Sql Server</title>

    <script runat=server>

    Public Sub Page_Load(sender As Object, e As EventArgs)

    ' Create Instance of Connection and Command Object

    Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

    Dim myCommand As New SqlCommand("Select * from Person", myConnection)

    Try

    myConnection.Open()

    Dim myDataReader as SqlDataReader

    myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)





    Do While (myDataReader.Read())

    Response.ContentType = myDataReader.Item("PersonImageType")

    Response.BinaryWrite(myDataReader.Item("PersonImage"))

    Loop



    myConnection.Close()

    Response.Write("Person info successfully retrieved!")

    Catch SQLexc As SqlException

    Response.Write("Read Failed : " & SQLexc.ToString())

    End Try

    End Sub



    </script>

    </HEAD>

    <body style="font: 10pt verdana">

    </body>

    <
Site designed by 中国财税咨询中心