|
| ||||||||||
| Tags: database, image, sql, vb dot net |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Adding Image in SQL database through vb.net application?
I want to know How can I add image to the SQL database through the form in my Vb.Net project. Can you guys please help me with the same? Regards, |
|
#2
| ||||
| ||||
| Re: Adding Image in SQL database through vb.net application? This source code is use to insert picture to SQL Server to binary format that is make the database.... Code: Function SaveImage _
(ByVal FileName As String) As Integer
' Create a FileInfo instance
' to retrieve the files information
Dim fi As New FileInfo(FileName)
' Open the Image file for Read
Dim imgStream As Stream = _
fi.OpenRead
' Create a Byte array the size
' of the image file for the Read
' methods buffer() byte array
Dim imgData(imgStream.Length) As Byte
imgStream.Read(imgData, 0, fi.Length)
Dim cn As New SqlConnection _
(ConfigurationSettings.AppSettings("cn"))
Dim cmd As New SqlCommand("Images_ins", cn)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
.Add("@FileName", VarChar, 100).Value = _
fi.Name
.Add("@FileType", VarChar, 10).Value = +
fi.Extension
.Add("@Image", Image).Value = imgData
.Add("@FileSize", Int, 4).Value = fi.Length
End With
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
cn.Dispose()
End Function |
|
#3
| ||||
| ||||
| Re: Adding Image in SQL database through vb.net application?
See the following links. Hope it will help u. http://www.codeproject.com/KB/web-image/PicManager.aspx http://www.vbdotnetheaven.com/Upload...SqlServer.aspx |
|
#4
| |||
| |||
| Re: Adding Image in SQL database through vb.net application?
ASP.NET/VB.NET Code to insert images in MS SQL Server Database. Follow this link! http://www.dotnetjunkies.com/WebLog/...les/39751.aspx |
|
#5
| |||
| |||
| Re: Adding Image in SQL database through vb.net application?
Here is the code to insert images to a Ms Access database! Code: File name is Image.vb
Imports System
Imports System.IO
Imports System.Data
Public Class SaveImage
Shared Sub main()
Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String
Console.Write("Enter a Valid .Gif file path")
gifFile = Console.ReadLine
If Dir(gifFile) = "" Then
Console.Write("Invalid File Path")
Exit Sub
End If
o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)
Try
Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New _ System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data
Source=Test.mdb")
Dim Sql As String = "INSERT INTO Images (Pic,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@FileSize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub
End Class |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Adding Image in SQL database through vb.net application?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Nokia C3-01 is not showing contact image after adding in favorites | chuck28 | Portable Devices | 4 | 04-09-2011 03:02 AM |
| Warning message when adding data to database | Jagavi | Software Development | 5 | 28-01-2010 03:40 PM |
| Problem regarding the adding my thumbnail image to file | reetus | Windows Software | 4 | 14-12-2009 04:23 PM |
| How to refresh database after adding a new record? | ArunJ | Software Development | 5 | 16-02-2009 06:27 PM |
| Insert image in access database from vb 6.0 | Vireshh | Software Development | 2 | 22-01-2009 08:06 PM |