A
Anthony Smales
I'm trying to display an images directly sourced from a SQL Server dbase,
and it would probably work but I can't get the connection string right!
I have tried just LOBSTER and (local), but still no good! In the Data Source
bit, should I be using a forward-slash or is it a double forward-slash?
Computer Name is LOBSTER
DBase is called 'Sandwich Shop Development'
Table is called 'Product'
There is no password on the dbase
Here is my code:
In webform1.aspx.vb, I have this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub
Public Sub BindGrid()
' Bind datagrid with dbase
Dim connstr As String = "Integrated Security=SSPI; Initial
Catalog=Sandwich Shop Development; Data Source=LOBSTER\localhost"
Dim cnn As New SqlClient.SqlConnection(connstr)
Dim da As New SqlClient.SqlDataAdapter("select * from Product", cnn)
Dim ds As New DataSet
da.Fill(ds, "Product")
DataGrid1.DataSource() = ds
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e
As DataGridItemEventArgs)
'ItemDataBound event
Dim img As System.Web.UI.WebControls.Image
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType
= ListItemType.Item Then
img = CType(e.Item.Cells(5).Controls(5),
System.Web.UI.WebControls.Image)
img.ImageUrl() = "WebForm2.aspx?id=" & e.Item.Cells(5).Text
End If
End Sub
In webform2.aspx.vb, I have this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Webform that returns image data
'Fetch image based on the query string passed
Dim connstr As String = "Integrated Security=SSPI; Initial
Catalog=Sandwich Shop Development; Data Source=LOBSTER\localhost"
Dim cnn As New SqlClient.SqlConnection(connstr)
Dim cmd As New SqlClient.SqlCommand("select * from Product where
ProductId=" & Request.QueryString("id"), cnn)
cnn.Open()
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim bindata() As Byte = dr.GetValue(5)
Response.BinaryWrite(bindata)
End Sub
and it would probably work but I can't get the connection string right!
I have tried just LOBSTER and (local), but still no good! In the Data Source
bit, should I be using a forward-slash or is it a double forward-slash?
Computer Name is LOBSTER
DBase is called 'Sandwich Shop Development'
Table is called 'Product'
There is no password on the dbase
Here is my code:
In webform1.aspx.vb, I have this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub
Public Sub BindGrid()
' Bind datagrid with dbase
Dim connstr As String = "Integrated Security=SSPI; Initial
Catalog=Sandwich Shop Development; Data Source=LOBSTER\localhost"
Dim cnn As New SqlClient.SqlConnection(connstr)
Dim da As New SqlClient.SqlDataAdapter("select * from Product", cnn)
Dim ds As New DataSet
da.Fill(ds, "Product")
DataGrid1.DataSource() = ds
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e
As DataGridItemEventArgs)
'ItemDataBound event
Dim img As System.Web.UI.WebControls.Image
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType
= ListItemType.Item Then
img = CType(e.Item.Cells(5).Controls(5),
System.Web.UI.WebControls.Image)
img.ImageUrl() = "WebForm2.aspx?id=" & e.Item.Cells(5).Text
End If
End Sub
In webform2.aspx.vb, I have this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Webform that returns image data
'Fetch image based on the query string passed
Dim connstr As String = "Integrated Security=SSPI; Initial
Catalog=Sandwich Shop Development; Data Source=LOBSTER\localhost"
Dim cnn As New SqlClient.SqlConnection(connstr)
Dim cmd As New SqlClient.SqlCommand("select * from Product where
ProductId=" & Request.QueryString("id"), cnn)
cnn.Open()
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim bindata() As Byte = dr.GetValue(5)
Response.BinaryWrite(bindata)
End Sub