VB.NET - PictureBox ImageLocation
Asked By Joseph on 11-Mar-10 08:59 AM
i have a problem. i need help in retrieving an image and placing it on a picture box.
the path is in the database. this is the code i used:
picbxBook.ImageLocation = (dtBook.Rows(rowPosition)("picture")
*dtBook is the name of the datatable and picture is the column heading where the path is stored.
i really need help. this is for my school work.
F Cali replied to Joseph on 11-Mar-10 09:10 AM
Are you getting any errors or the image is not showing? I am assuming that this is not the complete line in your code because this is missing a closing parenthesis:
picbxBook.ImageLocation = (dtBook.Rows(rowPosition)("picture"))
Are you expecting more than one row? If not, then try to hard-code it to row 0 and convert the value into string:
picbxBook.ImageLocation = Convert.ToString(dtBook.Rows(0)("picture"))
If this still doesn't work, post your code that loads the dtBook data table from the database.
Regards,
http://www.sql-server-helper.com/error-messages/msg-107.aspx
Joseph replied to F Cali on 11-Mar-10 09:23 AM
thank you for your help. it still doesn't work though.
i don't get a syntax error. the only error i think i get is that
the error image is displayed. the one with the "red x" thing
Here is the code when my form loads
Private Sub frmMoreInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbConn As New dbConn
dbConn.openDB()
strSQL = "Select * from tblBook where controlNo =" & frmSearch.ControlNo & ""
'"Welcome " & frmLogin.username & "!"
dtBook = dbConn.populateDT(strSQL)
dbConn.updateDB(dtBook)
dbConn.closeDB()
txtControlNo.Text = dtBook.Rows(rowPosition)("controlNo")
txtTitle.Text = dtBook.Rows(rowPosition)("title")
txtAuthor.Text = dtBook.Rows(rowPosition)("author")
txtGenre.Text = dtBook.Rows(rowPosition)("genre")
txtPublisher.Text = dtBook.Rows(rowPosition)("publisher")
txtStocks.Text = dtBook.Rows(rowPosition)("stocks")
txtLocation.Text = dtBook.Rows(rowPosition)("location")
txtSypnosis.Text = dtBook.Rows(rowPosition)("sypnosis")
' this is where i want to put the code to control the image of the picturebox
the other codes work well except for the code of the picture box.
i tried directly typing the path to check if the path has problems but the picture displayed.
i think i need to somehow conver the path/text i stored in my database so it would process it
like a normal path:
picbxBook.ImageLocation = "text in the database"
thanks again!
F Cali replied to Joseph on 11-Mar-10 09:28 AM
The value you set for the image location should include the whole path of where the image is located. If a relative path is used, it will be considered relative to the working directory.
Try debugging your application and see what value gets set in the image location and compare it to the value you set when you hard-code the image location.
Regards,
http://www.sql-server-helper.com/error-messages/msg-110.aspx
Joseph replied to F Cali on 11-Mar-10 09:40 AM
I used MsgBox (picbxBook.ImageLocation) to find out if they are the same
and they are. this is the path:
"C:\Users\JOSEPH\Documents\Visual Studio 2008\Projects\slnBookworm1.0\slnBookworm1.0\bin\Book Pics\newmoon.jpg"
the text in the directory is already enclosed in double quotation marks and the data type in the database is text.
F Cali replied to Joseph on 11-Mar-10 09:43 AM
When you say "the text in the directory is already enclosed in double quotation marks", do you mean that the value in the database has the double-quotation marks? If this is the case, then this is the cause of the image not displaying. You don't need the double quotation marks in the database value. Either you remove it in the database or you can remove it from code using the Replace method.
Regards,
http://www.sql-server-helper.com/error-messages/msg-128.aspx
Super Man replied to Joseph on 11-Mar-10 09:44 AM
Dim
imagepath As String
= dt.Rows(0).Item("picture").ToString()
Joseph replied to Super Man on 11-Mar-10 09:51 AM
it worked! :)
i removed the double quotation marks in the database.
thank you so much!
my inventory system is now complete.
thanks a lot!
Joseph replied to F Cali on 11-Mar-10 10:02 AM
it worked! :)
i removed the double quotation marks in the database.
thank you so much!
my inventory system is now complete.
thanks a lot!