J
James Page
Hi all another LINQ question!!
to retrieve and display sql varbinary images I currently use the following
code:
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Partial Class ShowPicture
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PictureID As Integer =
Convert.ToInt32(Request.QueryString("PictureID"))
'Connect to the database and bring back the image contents & MIME
type for the specified picture
Using myConnection As New
SqlConnection(ConfigurationManager.ConnectionStrings("ImageGalleryConnectionString").ConnectionString)
Const SQL As String = "SELECT [MIMEType], [ImageData] FROM
[Pictures] WHERE [PictureID] = @PictureID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@PictureID", PictureID)
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader
If myReader.Read Then
Response.ContentType = myReader("MIMEType").ToString()
Response.BinaryWrite(myReader("ImageData"))
End If
myReader.Close()
myConnection.Close()
End Using
End Sub
End Class
I'm now trying to use LINQ to replace the sql elements. Can anyone help me
convert the above using LINQ?
to retrieve and display sql varbinary images I currently use the following
code:
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Partial Class ShowPicture
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PictureID As Integer =
Convert.ToInt32(Request.QueryString("PictureID"))
'Connect to the database and bring back the image contents & MIME
type for the specified picture
Using myConnection As New
SqlConnection(ConfigurationManager.ConnectionStrings("ImageGalleryConnectionString").ConnectionString)
Const SQL As String = "SELECT [MIMEType], [ImageData] FROM
[Pictures] WHERE [PictureID] = @PictureID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@PictureID", PictureID)
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader
If myReader.Read Then
Response.ContentType = myReader("MIMEType").ToString()
Response.BinaryWrite(myReader("ImageData"))
End If
myReader.Close()
myConnection.Close()
End Using
End Sub
End Class
I'm now trying to use LINQ to replace the sql elements. Can anyone help me
convert the above using LINQ?