how to store file path in mysql database retrieve it using vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kumsay
    New Member
    • Jan 2013
    • 25

    how to store file path in mysql database retrieve it using vb.net

    hello, I have form with a listbox and a windows media player. The lisbox is populated with filename from the database. If the user select one item from listbox a video clip should play on the WMP. In the mysql database, I have a table VideoClips with fields vName(varchar), vLocation(varch ar). In vLocation I saved the file path of the picture (D:\VBProject\v ideos\video.flv ).
    Code:
    Call Connect()
            With Me
                STRSQL = "select vLocation from movie where vName = @vName"
                Try
                    myCmd.Connection = myConn
                    myCmd.CommandText = STRSQL
                    myReader = myCmd.ExecuteReader
                    myCmd.Parameters.AddWithValue("@vName", lstName.SelectedItem.ToString())
    
                    If myReader.Read Then
                        Dim path = myReader.GetString(0)
                        wmp.URL = path
                    End If
                Catch ex As Exception
                    MsgBox("no file")
                End Try
    
            End With
    there's no error, the problem is that when I select an item in the list it displays the catch exception message "no file" even if I already have the full path of the video stored in the database (example: D:\VBProject\vi deos\video.flv) . Can anybody help me work it properly? this is quite urgent, I need to finish this today. Please help me, God bless
  • kumsay
    New Member
    • Jan 2013
    • 25

    #2
    I browse and found a forum in the internet that \ should not be used because within MySQL string values the backslash is interpreted as an escape character and suggested to alter the path values to contain the "\" sequence to actually store a backslash. So I stored the file path as D:\\VBProject\\ videos\\sample. flv but still failed :(

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      The most likely problem is that you execute your reader before supplying the parameter value.

      Comment

      • VanessaMeacham
        New Member
        • Sep 2012
        • 31

        #4
        Hi ! i think it will help you

        [code]STRSQL = "Select pLocation From Pix where pixName = @pixName"
        myCmd.Parameter s.AddWithValue( "@pixName",lstP ix.SelectedItem .ToString())[/cod]e
        Last edited by Rabbit; Feb 4 '13, 05:36 PM. Reason: Please use code tags when posting code.

        Comment

        • kumsay
          New Member
          • Jan 2013
          • 25

          #5
          I already got it working, here's my working code:
          Code:
          Call Connect()
                  With Me
                      STRSQL = "select vLocation from movie where vName = '" & lstName.SelectedItem & "'"
                      Try
                          myCmd.Connection = myConn
                          myCmd.CommandText = STRSQL
                          myReader = myCmd.ExecuteReader
          
                          If myReader.Read Then
                              Dim path = myReader.GetString(0)
                              wmp.URL = path
          
                          End If
                      Catch ex As Exception
                          MsgBox("no file")
                      End Try
                    myConn.Close()
                  End With
          I stored the file path with single \ (D:\VBProject\v ideos\video.flv ). Thanks anyway :)

          Comment

          Working...