Images:
Table
CREATE TABLE dbo.STORED_IMAGES
(
ID int NOT NULL IDENTITY (1, 1),
Img varbinary(MAX) NULL
)
Storing Image:
Dim CMD As New SqlClient.SqlCommand("insert into STORED_IMAGES(Img) values(@Img)",cn)
CMD.Parameters.Add("@Img", SqlDbType.VarBinary, Integer.MaxValue).Value = ReadFile(Path)
Function for reading file:
Private Function ReadFile(sPath As String) As Byte()
Dim data As Byte() = Nothing
Dim fInfo As New IO.FileInfo(sPath)
Dim numBytes As Long = fInfo.Length
Using fStream As New IO.FileStream(sPath, IO.FileMode.Open, IO.FileAccess.Read)
Dim br As New IO.BinaryReader(fStream)
data = br.ReadBytes(CInt(numBytes))
End Using
Return data
End Function
Getting from DB:
Dim fcmd As New SqlCommand("select Img from STORED_IMAGES where ID=@ID", cn)
fcmd.Parameters.Add("@ID", SqlDbType.Int).Value = 3 'e.g.
Dim bytes As Byte() = fcmd.ExecuteScalar
Ref:
How to store and retrieve images in sql server database with vb.net[
^]
Refer:
Save and retrieve images with SQL Server [
^]
Storing images in SQL Server 2005 and retrieving them from VB.NET[
^]
Excel Files:
Retrieve excel file stored in sql server using vb.net[
^]