Monday, January 04, 2010

How can you save a MS Office file into a database?

If you want to save a MS Office document such as 
Word doc in a database, you can do it with the 
following code:

    Dim vStream As New FileStream("C:\Alex.doc", FileMode.Open) 
    Dim vLen As Integer = New FileInfo("C:\Alex.doc").Length
    Dim vBlob(vLen) As Byte
    Dim n As Integer = vStream.Read(vBlob, 0, vLen)
    Dim vSql As String = 
"INSERT INTO tBlobTable (vId,vBlob) VALUES (1,@vBlob)" 
    Dim sql As New SqlCommand(vSql, vConn)
    Dim sqlPar As New SqlParameter("@vBlob", SqlDbType.Image)
    sqlPar.Value = vBlob

I hope you would find it useful.

SQL Server Query: Fast with Literal but Slow with Variable

Often when there is a drastic difference from run to run of a query I find that it is often one of 5 issues. STATISTICS  - Statistics a...