Herbert Posted April 12, 2018 at 12:30 PM Report #610197 Posted April 12, 2018 at 12:30 PM Ola a todos! Queria saber como fazer para armazenar um arquivo de videos no banco de dados access usando visual.net ? Tenho um formulário de cadastro pronto no visual studio e todos os outros compros estão pronto só falta eu conseguir um método de armazena vídeos no banco de dados. Obrigado! 1 Report
Estuardo Posted July 31, 2018 at 10:06 PM Report #611466 Posted July 31, 2018 at 10:06 PM Boa noite, Quase qualquer tipo de ficheiro pode ser convertido em stream e ser guardado numa coluna tipo OLE Object. algo assim: Private Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click Dim fdlgbox As New OpenFileDialog() fdlgbox.Filter = "All Files (.*)|*.*" fdlgbox.ShowDialog() If fdlgbox.FileName.Trim() <> "" Then Dim ofile() As Byte = Nothing ofile = GetStream(fdlgbox.FileName.Trim()) SaveToDb(fdlgbox.SafeFileName.Trim(), ofile) 'Get Just FileName with Extention End If End Sub Private Function SaveToDb(strFileName As string ,fileStream As Byte()) As Boolean 'your saving process here (entity framework, ado.net, dapper etc) End Function Public Shared Function GetStream(ByVal filePath As String) As Byte() Dim buffer() As Byte Dim fileStream As New FileStream(filePath, FileMode.Open, FileAccess.Read) Try Dim length As Integer = CInt(Fix(fileStream.Length)) ' get file length buffer = New Byte(length - 1){} ' create buffer Dim count As Integer ' actual number of bytes read Dim sum As Integer = 0 ' total number of bytes read ' read until Read method returns 0 (end of the stream has been reached) count = fileStream.Read(buffer, sum, length - sum) Do While count > 0 sum += count ' sum is a buffer offset for next reading count = fileStream.Read(buffer, sum, length - sum) Loop Finally fileStream.Close() End Try Return buffer End Function 1 Report
Herbert Posted July 31, 2018 at 10:23 PM Author Report #611470 Posted July 31, 2018 at 10:23 PM Obrigado, vou tentar fazer conforme a resposta
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now