Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL2000 VB.NET
Bro can you help me, please!
 
How to store and retrieve file excel in sql server database through VB.NET
 

 
thanks,
Posted 8-Jun-12 0:32am
Edited 8-Jun-12 0:40am
v2
Comments
codeBegin at 8-Jun-12 5:33am
   
Excel or images what exactly your requirement is??
losmac at 8-Jun-12 18:21pm
   
What it mean: BRO?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
maddoxcom at 8-Jun-12 5:42am
   
sorry bro not image but file ex: excel or doc
and retrieve from database become file again
 
thanks
Dave Kreskowiak at 8-Jun-12 9:41am
   
The process is exactly the same. Whether it's an image or an Excel file, a file is just a stream of bytes! It makes no difference to SQL Server what that stream represents.
losmac at 8-Jun-12 18:22pm
   
Good work! +5
maddoxcom at 12-Jun-12 7:44am
   
oke thanks bro
but
sorry bro I'm Junior
want to ask again
after this proses
'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'
 
how to make excel file again
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi maddoxcom,
Go through this link-
Store file in database[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.150301.1 | Last Updated 11 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100