Hi, I've looked in a few places but haven't had much luck in finding what I'm after.
So I have a picturebox on my windows form and it has an image set to it, I also have a bunch of reference files that reference to a bunch of images.
That piece of code works.
Now, I tried to databind the picture box to a database so the images would load on the change of a combo box but that got confusing really fast so what I did was created a database and it holds all the image references such as "My.Resources.imgs.image1" but its stored as type varchar(50).
Connecting to the database and retreiving the strings is no problem, that works all fine.
The problem is converting the string to the image reference, it doesn't work. I've tried type casting, I tried using imagelocation rather than image but I want to reference to the resources that is attached to the project.
Can anyone help me with this issue? - Thanks
Here is the full code, incase it helps
So I have a picturebox on my windows form and it has an image set to it, I also have a bunch of reference files that reference to a bunch of images.
VB.NET:
Me.PictureBox1.Image = My.Resources.imgs.image1
That piece of code works.
Now, I tried to databind the picture box to a database so the images would load on the change of a combo box but that got confusing really fast so what I did was created a database and it holds all the image references such as "My.Resources.imgs.image1" but its stored as type varchar(50).
Connecting to the database and retreiving the strings is no problem, that works all fine.
The problem is converting the string to the image reference, it doesn't work. I've tried type casting, I tried using imagelocation rather than image but I want to reference to the resources that is attached to the project.
Can anyone help me with this issue? - Thanks
Here is the full code, incase it helps
VB.NET:
Imports System.Data.SqlClient 'before class constructor
Dim SQLStr As String
Private ConnString As String
'after class constructor'the following is within a sub
ConnString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\statsdata.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
SQLStr = "SELECT imgreference FROM tblImages WHERE (number = " + Me.ComboBox1.SelectedIndex + ")"
Dim SQLConn As New SqlConnection() 'The SQL Connection
Dim SQLCmd As New SqlCommand() 'The SQL Command
Dim SQLdr As SqlDataReader 'The Local Data Store
Dim text As String
Dim img As Image = Nothing
SQLConn.ConnectionString = ConnString 'Set the Connection String
Try
SQLConn.Open() 'Open the connection
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
SQLCmd.CommandText = SQLStr 'Sets the SQL String
SQLdr = SQLCmd.ExecuteReader() 'Executes SQL Commands
SQLdr.Read()
text = SQLdr.GetString(0)
SQLdr.Close() 'Close the SQLDataReader
SQLConn.Close() 'Close the connection
'This is where I would change the reference of the image
'E.g. Me.PictureBox1.Image = text - except I have to cast text from type String to type Image
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Somethings wrong!!")
End Try