Hi all another LINQ question!!
to retrieve and display sql varbinary images I currently use the following
code:
Imports System.Data.Sql Client
Imports System.Drawing
Imports System.Drawing. Imaging
Imports System.IO
Partial Class ShowPicture
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim PictureID As Integer =
Convert.ToInt32 (Request.QueryS tring("PictureI D"))
'Connect to the database and bring back the image contents & MIME
type for the specified picture
Using myConnection As New
SqlConnection(C onfigurationMan ager.Connection Strings("ImageG alleryConnectio nString").Conne ctionString)
Const SQL As String = "SELECT [MIMEType], [ImageData] FROM
[Pictures] WHERE [PictureID] = @PictureID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Param eters.AddWithVa lue("@PictureID ", PictureID)
myConnection.Op en()
Dim myReader As SqlDataReader = myCommand.Execu teReader
If myReader.Read Then
Response.Conten tType = myReader("MIMET ype").ToString( )
Response.Binary Write(myReader( "ImageData" ))
End If
myReader.Close( )
myConnection.Cl ose()
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.Sql Client
Imports System.Drawing
Imports System.Drawing. Imaging
Imports System.IO
Partial Class ShowPicture
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim PictureID As Integer =
Convert.ToInt32 (Request.QueryS tring("PictureI D"))
'Connect to the database and bring back the image contents & MIME
type for the specified picture
Using myConnection As New
SqlConnection(C onfigurationMan ager.Connection Strings("ImageG alleryConnectio nString").Conne ctionString)
Const SQL As String = "SELECT [MIMEType], [ImageData] FROM
[Pictures] WHERE [PictureID] = @PictureID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Param eters.AddWithVa lue("@PictureID ", PictureID)
myConnection.Op en()
Dim myReader As SqlDataReader = myCommand.Execu teReader
If myReader.Read Then
Response.Conten tType = myReader("MIMET ype").ToString( )
Response.Binary Write(myReader( "ImageData" ))
End If
myReader.Close( )
myConnection.Cl ose()
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?
Comment