Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 426

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/templates/ja_purity/ja_templatetools.php on line 49
Insert image to database using VB.NET - The Scripts Library Community

Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home Visual Basic.NET Insert image to database using VB.NET

Insert image to database using VB.NET

E-mail
(0 votes, average: 0 out of 5)

Here is a simple example of how to insert an image into a SQL Server database. The image will be stored as a binary file.


 
Sub SaveImage()

Dim con As New SqlClient.SqlConnection("connection string goes here")
Dim cmd As SqlClient.SqlCommand()

cmd = New SqlClient.SqlCommand("Insert into tableName (Image) Values(@image)", con)
'Use may fileUplaod control to select your image
Using nPic As Image = Image.FromFile("image path goes here")
Using stream As New IO.MemoryStream
nPic.Save(stream, Imaging.ImageFormat.Gif)
cmd.Parameters.Add("@image", SqlDbType.VarBinary).Value = stream.GetBuffer()
End Using
End Using
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub

You can use a FileUpload to specify the path of the image.