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 : PopUp Page with RG.Plugins.Popup

Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)