M
mosipenko
I have a website that has articles and images. The articles are stored
in one table, and if they have an image associated with them, it's
stored in another table with a common id linking them. I can pull all
the information fine into labels, and if the ImagePath field is NULL,
then it just doesn't show up. My problem is that when I'm trying to
display the images, I get a "Conversion from type 'DBNull' to type
'String' is not valid" error when that field is NULL. How can I get
this to work??
This is my code on the aspx page to display the image:
<img src='\main\content\images\<%#
System.IO.Path.GetFileName(Eval("ImagePath"))%>' width="150px">
This is my code on the aspx.vb page to pull the image:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim connStr As String = "Data Source=server;Initial
Catalog=database; User ID=user;Password=password;"
Dim connObj As SqlClient.SqlConnection = New
SqlClient.SqlConnection
Dim connCmd As New SqlClient.SqlCommand
Dim strID As String
strID = Request.QueryString("cidL")
Dim selectstr As String = "Select ImagePath from Image where
cid='" + strID + "'"
Dim dataread As SqlClient.SqlDataReader
Dim unameexists As Boolean
connObj.ConnectionString = connStr
connObj.Open()
connCmd.CommandText = selectstr
connCmd.Connection = connObj
dataread = connCmd.ExecuteReader()
DataList1.DataBind()
dataread.Close()
End Sub
in one table, and if they have an image associated with them, it's
stored in another table with a common id linking them. I can pull all
the information fine into labels, and if the ImagePath field is NULL,
then it just doesn't show up. My problem is that when I'm trying to
display the images, I get a "Conversion from type 'DBNull' to type
'String' is not valid" error when that field is NULL. How can I get
this to work??
This is my code on the aspx page to display the image:
<img src='\main\content\images\<%#
System.IO.Path.GetFileName(Eval("ImagePath"))%>' width="150px">
This is my code on the aspx.vb page to pull the image:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim connStr As String = "Data Source=server;Initial
Catalog=database; User ID=user;Password=password;"
Dim connObj As SqlClient.SqlConnection = New
SqlClient.SqlConnection
Dim connCmd As New SqlClient.SqlCommand
Dim strID As String
strID = Request.QueryString("cidL")
Dim selectstr As String = "Select ImagePath from Image where
cid='" + strID + "'"
Dim dataread As SqlClient.SqlDataReader
Dim unameexists As Boolean
connObj.ConnectionString = connStr
connObj.Open()
connCmd.CommandText = selectstr
connCmd.Connection = connObj
dataread = connCmd.ExecuteReader()
DataList1.DataBind()
dataread.Close()
End Sub