PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] VS2015 how do i load a picture when i select a customer from datagrid ?-VBForums
Results 1 to 8 of 8

Thread: [RESOLVED] VS2015 how do i load a picture when i select a customer from datagrid ?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,703

    Resolved [RESOLVED] VS2015 how do i load a picture when i select a customer from datagrid ?

    hey
    i am trying to load a picture that i stored before to a picture box
    i cant find a way
    all i can do is just retrieve another data
    this is my code
    Code:
        Private Sub dgCustomers_Click(sender As Object, e As EventArgs) Handles dgCustomers.Click
                Dim sql As String = "Select * From Customers Where FullName = '" & 
                dgCustomers.SelectedCells(1).Value & "'"
                Cmd = New SqlCommand(sql, Cn)
                Dr = Cmd.ExecuteReader
                While Dr.Read
                    txtaddress.Text = Dr.GetValue(2).ToString
              End While
        End Sub
    the name of the picturebox is PicCust
    the value in the sql is 10

    tnx allot
    salsa

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,586

    Re: how do i load a picture when i select a customer from datagrid ?

    Quote Originally Posted by salsa31 View Post
    i am trying to load a picture that i stored before to a picture box
    You should probably explain what that actually means. If you have already retrieved the data from the database then why are you executing a query at all?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,703

    Re: how do i load a picture when i select a customer from datagrid ?

    when i press a certain row in the datagrid then i am displaying in the form the details
    like address and phone.
    what i want to do is also display the photo that i stored for this customer in the picture that is on the form
    and i dont know how.
    all i know is how to get the text value like this
    Code:
    txtaddress.Text = Dr.GetValue(2).ToString

  4. #4

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,703

    Re: how do i load a picture when i select a customer from datagrid ?

    this is not working
    Code:
    PicCust.Image = Dr.GetValue(10)

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,703

    Re: how do i load a picture when i select a customer from datagrid ?

    i think i got it
    Code:
    PicCust.Image = Image.FromFile(Dr.GetValue(10))
    but just trying to know if its null then i use this ?
    Code:
     If IsDBNull(Dr.GetValue(10)) Then
    Last edited by salsa31; Nov 8th, 2018 at 08:19 AM.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,586

    Re: how do i load a picture when i select a customer from datagrid ?

    You would not do this:
    vb.net Code:
    1. If IsDBNull(Dr.GetValue(10)) Then
    but rather this:
    vb.net Code:
    1. If Dr.IsNull(10) Then
    Also, you shouldn't create the Image yourself when the PictureBox has an ImageLocation property and a Load method.
    vb.net Code:
    1. PicCust.ImageLocation = If(Dr.IsNull(10), CStr(Nothing), CStr(Dr.GetValue(10)))
    I'm not 100% sure that setting the ImageLocation to Nothing will clear the current Image but it seems logical, so you should test whether it does.

    Actually, you could simplify that further like so:
    vb.net Code:
    1. PicCust.ImageLocation = Dr.Field(Of String)(10)
    That Field method will return a String if there is one and Nothing otherwise.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,703

    Re: how do i load a picture when i select a customer from datagrid ?

    If Dr.IsNull(10) Then
    there is only IsDBNull



    this is working perfect
    Code:
    PicCust.ImageLocation = Dr.GetFieldValue(Of String)(10)

    i will also try this
    Code:
    PicCust.ImageLocation = If(Dr.IsNull(10), CStr(Nothing), CStr(Dr.GetValue(10)))
    thank you very much

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,586

    Re: how do i load a picture when i select a customer from datagrid ?

    Quote Originally Posted by salsa31 View Post
    there is only IsDBNull



    this is working perfect
    Code:
    PicCust.ImageLocation = Dr.GetFieldValue(Of String)(10)

    i will also try this
    Code:
    PicCust.ImageLocation = If(Dr.IsNull(10), CStr(Nothing), CStr(Dr.GetValue(10)))
    thank you very much
    That all suggests that Dr is a data reader rather than the DataRow that I assumed that it was. See, when I said that you should explain back in post #2, I meant a FULL and CLEAR explanation. Why would you be using a data reader if you have data in a grid? Surely you have populated a DataTable and have bound it to the grid and then, when the user selects a row in the grid, you are accessing the bound DataRow and getting the file path from that. If you're not doing that, you should be. Of course, what you are doing would be included in that explanation that you should always provide at the start so that we don't have to guess or assume things.
    Last edited by jmcilhinney; Nov 8th, 2018 at 09:39 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width