This code will save an image file to SQL Server. The key is that the image datatype in SQL Server is equivalent to a byte array in .net.
Code:' dimension an image variable myImage as New Bitmap myImage.FromFile("c:\test.jpg") ' dimension a memory stream to hold contents of image Dim myStream As New IO.MemoryStream() ' load imagebox image into memory stream myImage.Save(myStream, Drawing.Imaging.ImageFormat.Jpeg) ' establish database connection Dim cn As New SqlClient.SqlConnection("data source=MYDATASOURCE;initial catalog=MYDATABASE;persist security info=False;user id=sa;workstation id=SHX20476;packet size=4096;password=mypassword") ' create SQL statement with image parameter Dim cmd As New SqlClient.SqlCommand("Insert Into ImageTable (imageid, image) Values ('12345',@Picture)", cn) ' define image parameter content from memory stream Dim P As New SqlClient.SqlParameter("@Picture", SqlDbType.Image, myStream.ToArray.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, myStream.ToArray()) ' add parameter cmd.Parameters.Add(P) ' open database and execute command to store image cn.Open() cmd.ExecuteNonQuery() cn.Close()




