VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,833 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,770 people online right now. Registration is fast and FREE... Join Now!




save a zip file in a sql database using vb.net

 

save a zip file in a sql database using vb.net

goldjoat

7 May, 2009 - 05:38 AM
Post #1

New D.I.C Head
*

Joined: 7 May, 2009
Posts: 1

Hi @all,

I need your help: I want to save a zip file at a sql database.
I tried to to the same like saving txt files, but if I want to open the saved file (it was created from a stream)
the zip file is coruppted!

saving zip file as stream
CODE


                        Dim fs As New FileStream(tmpPfad, FileMode.Open, FileAccess.Read)
                        Dim bytData(fs.Length() - 1) As Byte
                        fs.Read(bytData, 0, bytData.Length)
                        fs.Close()
                        Dim i As Integer
                        Dim tmpSQLUpdate As New SqlClient.SqlCommand()
                        tmpSQLUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@FFile", SqlDbType.Image, bytData.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, bytData))
                        tmpSQLUpdate.CommandText = "update tblfiles set ffile = @ffile where ID = 1"



open stream as zip file
CODE


                    Dim MyData() As Byte
                    MyData = Me.OpenRowSelection.Item(0).Cells("File").Value '(Bytestream)
                    Dim K As Long
                    K = UBound(MyData)
                    'Dim tmpPfad As String = "d:\tmp\"
                    tmpPfad += Me.OpenRowSelection.Item(0).Cells("ID").Value.ToString + "." +  me.OpenRowSelection.Item(0).Cells("Ext").Value.ToString
                  
                    Dim fs As New FileStream(tmpPfad, FileMode.Create, FileAccess.Write)
                    fs.Write(MyData, 0, K)
                    fs.Close()
                    fs = Nothing




User is offlineProfile CardPM
+Quote Post


JackOfAllTrades

RE: Save A Zip File In A Sql Database Using Vb.net

7 May, 2009 - 07:52 AM
Post #2

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,311



Thanked: 453 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
You might have more luck in VB.NET, so I'll move you there.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 11:00PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month