Results 1 to 3 of 3

Thread: populate a db table with pictures!!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    94

    populate a db table with pictures!!!!

    Dear all,

    I have to populate an sql database table with pictures. The table has products with their product_id.
    In a folder I have all the pictures in the format product_id.jpg.

    I need to compare each row of the table Product_id with the file name’s in the folder and if they are the same update the product row in the table with the image.

    I have used MyFolderBrowser in order to select the folder that contains photos.
    1)Which is the command in order to read the first file in the folder ???

    The files, in the folder, are in the following format = 01-10-MUYE200.jpg
    2)How can i read each file name till the DOT and compare it with a specific field in an sql table ????


    Thanks in advance,

    Best Regards,

    RH

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: populate a db table with pictures!!!!

    The following returns all files with an extension of JPG. In the For/Each loop the file name only is displayed.

    Code:
    Dim Files As String() = IO.Directory.GetFiles( _
        MyFolderBrowser.SelectedPath, "*.jpg")
    
    If Files.Count > 0 Then
        For Each File In Files
            Console.WriteLine("{0}", _
                IO.Path.GetFileNameWithoutExtension(File))
        Next
    End If
    For comparison a WHERE clause in a SELECT SQL statement

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: populate a db table with pictures!!!!

    I think that your best bet would be:

    1. Use a data adapter to populate a DataTable with all the records.
    2. Get a list of all the file names.
    3. Loop through the list of file names.
    4. For each file name, find the matching row, if there is one.
    5. Add the image data to the row.
    6. When the loop is done, use the data adapter to save the whole DataTable back to the database.

    If you follow the CodeBank link in my signature, you'll find a thread on Saving Images In Databases that will show you how to get the Image data into and out of the database.
    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
  •  



Click Here to Expand Forum to Full Width