There are various steps to store a image in sql Server 2008, That are given bellow:
Create a table with two columns id (int) and img (image): CREATE TABLE [dbo].[imgtable]( [id] [int] NULL, [img] [image] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Design a window form with a Button1:
Write these coding of Button1: Imports System.Data.SqlClientImports System.IO Public Class Form1 Dim s1 As String Private Sub Button1_Click(ByVal senderAs System.Object, ByVal e As System.EventArgs)Handles Button1.Click Dim str As String = "Data Source=MCNDESKTOP14;Initial Catalog=studentinfo; uid=sa;pwd=wintellect" Dim conAs SqlConnection con = New SqlConnection(str) Dim fName As String fName = "D:\picture\aur2.jpg" If File.Exists(fName)Then Dim idAs Integer = 1 Dim contentAs Byte() = ImageToStream(fName) con.Open() Dim cmd As New SqlCommand("insert into imgtable (id,img) values ( @id,@img)", con) cmd.Parameters.AddWithValue("@id", id) cmd.Parameters.AddWithValue("@img", content) cmd.ExecuteNonQuery() con.Close() MsgBox("Image inserted") Else MsgBox(fName & " not found ") End If End Sub Private Function ImageToStream(ByVal fileNameAs String)As Byte() Dim stream As New MemoryStream()tryagain: Try Dim imageAs New Bitmap(fileName) image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg) Catch ex As Exception GoTo tryagain End Try Return stream.ToArray() End Function End Class
Output:
How to insert the image in sql server 2008 using VB.NET
How to Create Asynchronous Login Form in ADO.NET
Hi I Downloaded Your Sample Application I Have executed it Id Is Inserted While content Is Not I Tried It Through SQL Query window Its OK Id And Image Are Inserted. Also If Possible How Can I Retrieve Image And Display On A Form. Much Appreciated