School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,049 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,527 people online right now. Registration is fast and FREE... Join Now!



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

Page 1 of 1

save a zip file in a sql database using vb.net Rate Topic: -----

#1 goldjoat  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 07-May 09


Dream Kudos: 0

Posted 07 May 2009 - 05:38 AM

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
 

						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
 

					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


Was This Post Helpful? 0
  • +
  • -


#2 JackOfAllTrades  Icon User is online

  • Mayor of Simpleton
  • Icon
  • View blog
  • Group: Moderators
  • Posts: 7,122
  • Joined: 23-August 08


Dream Kudos: 50

Expert In: Being annoyed with lazy people.

Posted 07 May 2009 - 07:52 AM

You might have more luck in VB.NET, so I'll move you there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month