Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Hi Friends,

As i am new to you give me a suggestion for how to insert image into
sql database
Posted 21-Jul-12 0:06am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

1) Bring up SQL Server Management Studio.
2) Connect, and open the database you want to add the image to.
3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design.
4) Add a field called "myImage", and make its datatype "image". Allow nulls.
5) Close SQL Server Management studio.
To add images to the table (I will assume a new record, the table has an Identity field, and just the myImage column):
Using con As New SqlConnection(connectionString)
	Using com As New SqlCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con)
		Dim imageData As Byte() = File.ReadAllBytes("D:\Temp\Picture.jpg")
		com.Parameters.AddWithValue("@IM", imageData)
	End Using
End Using

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 400
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 245
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175

Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 21 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100