|
-
Sep 8th, 2011, 08:14 AM
#1
Thread Starter
Lively Member
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
-
Sep 8th, 2011, 04:45 PM
#2
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
-
Sep 8th, 2011, 10:17 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|