Store Image From Picture Box To SQL SERVER


My New Task

Save Image from Picturebox to Sql Server Table.

Dim stream As New MemoryStream()
picEmp.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)

Dim oImgByteArray() As Byte
oImgByteArray()  = stream.ToArray


Dim SQLCmd As New SqlCommand
SQLCmd.Connection = cnSQL

SQLCmd.Parameters.Add(New SqlParameter("@Img", SqlDbType.Image)).Value = oImgByteArray


SQLCmd.CommandText = "Insert Into CMS.mastImageStoreage (Img) Values (@Img)"
SQLCmd.ExecuteNonQuery()

stream.close
SQLCmd.Dispose


Note : This is why love working on .net platform. If you were suppose perform same in VB 6.0. Physical file is need in path and than only you can save. Think  bring same from database. You have create physical file in drive and load it from there. 

Comments

Popular posts from this blog

Shared / Static Class in vb.net/C#

Xamarin Forms - Change Colour of Navigation Bar (Page Title For Master-Detail Template)

How to Download File using HTTP - VB.net