Question Import/Store any Files into SQL Column

tanero82

New member
Joined
Jun 1, 2009
Messages
2
Programming Experience
Beginner
Hello, i am a beginner and need some help plz. I have created an Adressbook Project and want to import (openfiledialog) any typ of File - in most case "Jpeg, docx" etc.

I have created a Database on SQL 2005 with 1 Table. The Table consist 6 Columns (ID=Primärykey, Name, Address, Data=Type Image and so on).
In my VS 2008 i created a Database Connection to the DB. I put the textboxes/connection from the Database per Drag and Drop on my Form (with "BindingNavigator").
So a can wonderful add, change, delete the entry on my form.

And here is my Problem:
I would like to import a file into the specified Column. For Example a Picture of the selected Contact.

I have tried to import the File with a Manual which i found on msdn (Blob-binary). The Import sucess but the Import makes a new row. I want to bound the Import to the selected Contact.
Is there any way to complete this?
Please help i try to complete since 3 day without sucess :confused:

Thx a lot
Best Regards Tanero
 
First up, don't use the 'image' data type in SQL Server as it is deprecated. Use the 'varbinary' data type.

As for the question, saving and retrieving binary data is exactly like saving and retrieving any other data. If you want to set a field value in an existing record then you execute an UPDATE statement and specify the ID of that record. If you want to add a new record you execute an INSERT statement.

For binary data the VB type you use to save and retrieve data is a Byte array. The simplest way to get a Byte array from a file is the File.ReadAllBytes method. There is a corresponding WriteAllBytes method to save binary data to a file.
 

Latest posts

Back
Top