Source: www.aspalliance.com Introduction: This article is follow-up of "how to put pictures in SQLServer". I suggest you look at that article before reading this article. Reading images simply more than storage images. Output a picture of the picture we have to do is the BinaryWrite method using the Response object. Set the format of the picture at the same time. In this article, we will discuss how to retrieve images from SQL Server. And will learn the following knowledge. • How to set the format of the picture? · How to use a binarywrite method. We have stored data in the Person table, then we write some code to read data from the table. The following code retrieves all values from the Person table. Sqlserver image read from the code .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 see him How did you work? The above example is simple. What we do is to execute a SQL statement, read all records (Looping Through the records). Before displaying the image, we set the contentType of the picture first, and then we use the binarywrite method to output the image to the browser.
Source code: /// retriving.aspx <% @ page language = "vb"%> <% @ import name "%> <% @ import name"%> system.data.sqlclient "%>