Usuário com melhor resposta
VB.NET \ Access

Pergunta
-
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 (Eu consigo importa videos direto pelo o access, mas quero saber como fazer pelo vb.net)
Obrigado!
Respostas
-
Boa noite
O processo é o mesmo que para armazenar imagens, ou seja, convertendo o arquivo em bytes().
Deixo um exemplo onde troque imagem por video:
Public Class FRM_Cadastro_Video Dim Ar_byte() As Byte Private Sub BU_Localiza_Video_Click(sender As System.Object, e As System.EventArgs) Handles BU_Localiza_Video.Click pic_Ass.Image = Nothing OpenFile.FileName = "" OpenFile.Filter = "Videos - *.mp4|*.mp4" OpenFile.InitialDirectory = Application.StartupPath & "\Configurações" OpenFile.ShowDialog() If OpenFile.FileName <> "" Then Try Dim fs As New FileStream(OpenFile.FileName, FileMode.Open) ReDim Ar_byte(CInt(fs.Length)) fs.Read(Ar_byte, 0, Ar_byte.Length) fs.Close() Catch ex As Exception MessageBox.Show(ex.ToString, Proj, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try Else Ar_byte = Nothing End If End Sub Private Sub Sub_Salvar() BD.Cadastro_Video("Incluir", txt_Nome_Video.Text, Ar_byte) End Sub Private Sub Datagrid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DG.Click Sub_PreencheLocalizar() End Sub Private Sub Sub_PreencheLocalizar() Try Sub_Cancelar() txt_Nome_Video.Text = DG(0, DG.CurrentRow.Index).Value.ToString If BD.Cadastro_Video("Localizar_Video", txt_Nome_Video.Text, "", Ar_byte) = -1 Then Exibe_Erro() Else Dim fsImage As New FileStream("video.mp4", FileMode.Create) fsImage.Write(Ar_byte, 0, Ar_byte.Length) fsImage.Close() fsImage = Nothing End If Catch ex As Exception Psr_Erro = ex.ToString End Try End Sub End Class Public Class BD Public Shared Function Cadastro_Video(ByVal O_que As String, ByVal Lsr_Login As String, ByRef Ar_Assinatura() As Byte) As Int32 Dim CONN As New OleDbConnection() CONN.ConnectionString = Psr_ConnectionString Dim CMD As OleDbCommand = CONN.CreateCommand Try CONN.Open() Select Case O_que Case "Incluir" CMD.CommandText = "insert into cadastro_operadores values (" & Psr_ID_CCB & ", '" & Lsr_Login & "', '" & Lsr_Senha & "', ?, #" & Now.ToString("MM/dd/yyyy HH:mm:ss") & "#, '" & Psr_Operador & "')" If Not IsNothing(Ar_Assinatura) Then CMD.Parameters.AddWithValue("@ass", Ar_Assinatura) Else CMD.Parameters.AddWithValue("@ass", DBNull.Value) End If CMD.ExecuteNonQuery() Case "Localizar_Video" Dim RD As OleDbDataReader CMD.CommandText = "select oper_ass from cadastro_operadores where oper_login = '" & Lsr_Login & "' and oper_ccb = " & Psr_ID_CCB RD = CMD.ExecuteReader If Not RD.HasRows Then RD.Close() Else RD.Read() If Not (IsNothing(RD(0)) OrElse IsDBNull(RD(0))) Then Ar_Assinatura = CType(RD(0), Byte()) RD.Close() End If End Select CONN.Close() Return 1 Catch ex As Exception If CONN.State = 1 Then CONN.Close() Psr_Erro = ex.ToString Return -1 End Try End Function End Class
MARIANO1776
- Editado Mariano1776 domingo, 15 de abril de 2018 23:18
- Sugerido como Resposta Lucio Rogerio SPBanned segunda-feira, 16 de abril de 2018 12:18
- Marcado como Resposta Filipe B CastroModerator quarta-feira, 2 de maio de 2018 21:37
Todas as Respostas
-
Boa tarde, Hagar07.01. Tudo bem?
Obrigado por usar o fórum MSDN.
Essa seria uma questão de "Break Fix/Erro" ou "How to/Customização"?
Atenciosamente,Filipe B de Castro
Esse conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita
MSDN Community Support
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.
-
-
Boa noite
O processo é o mesmo que para armazenar imagens, ou seja, convertendo o arquivo em bytes().
Deixo um exemplo onde troque imagem por video:
Public Class FRM_Cadastro_Video Dim Ar_byte() As Byte Private Sub BU_Localiza_Video_Click(sender As System.Object, e As System.EventArgs) Handles BU_Localiza_Video.Click pic_Ass.Image = Nothing OpenFile.FileName = "" OpenFile.Filter = "Videos - *.mp4|*.mp4" OpenFile.InitialDirectory = Application.StartupPath & "\Configurações" OpenFile.ShowDialog() If OpenFile.FileName <> "" Then Try Dim fs As New FileStream(OpenFile.FileName, FileMode.Open) ReDim Ar_byte(CInt(fs.Length)) fs.Read(Ar_byte, 0, Ar_byte.Length) fs.Close() Catch ex As Exception MessageBox.Show(ex.ToString, Proj, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try Else Ar_byte = Nothing End If End Sub Private Sub Sub_Salvar() BD.Cadastro_Video("Incluir", txt_Nome_Video.Text, Ar_byte) End Sub Private Sub Datagrid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DG.Click Sub_PreencheLocalizar() End Sub Private Sub Sub_PreencheLocalizar() Try Sub_Cancelar() txt_Nome_Video.Text = DG(0, DG.CurrentRow.Index).Value.ToString If BD.Cadastro_Video("Localizar_Video", txt_Nome_Video.Text, "", Ar_byte) = -1 Then Exibe_Erro() Else Dim fsImage As New FileStream("video.mp4", FileMode.Create) fsImage.Write(Ar_byte, 0, Ar_byte.Length) fsImage.Close() fsImage = Nothing End If Catch ex As Exception Psr_Erro = ex.ToString End Try End Sub End Class Public Class BD Public Shared Function Cadastro_Video(ByVal O_que As String, ByVal Lsr_Login As String, ByRef Ar_Assinatura() As Byte) As Int32 Dim CONN As New OleDbConnection() CONN.ConnectionString = Psr_ConnectionString Dim CMD As OleDbCommand = CONN.CreateCommand Try CONN.Open() Select Case O_que Case "Incluir" CMD.CommandText = "insert into cadastro_operadores values (" & Psr_ID_CCB & ", '" & Lsr_Login & "', '" & Lsr_Senha & "', ?, #" & Now.ToString("MM/dd/yyyy HH:mm:ss") & "#, '" & Psr_Operador & "')" If Not IsNothing(Ar_Assinatura) Then CMD.Parameters.AddWithValue("@ass", Ar_Assinatura) Else CMD.Parameters.AddWithValue("@ass", DBNull.Value) End If CMD.ExecuteNonQuery() Case "Localizar_Video" Dim RD As OleDbDataReader CMD.CommandText = "select oper_ass from cadastro_operadores where oper_login = '" & Lsr_Login & "' and oper_ccb = " & Psr_ID_CCB RD = CMD.ExecuteReader If Not RD.HasRows Then RD.Close() Else RD.Read() If Not (IsNothing(RD(0)) OrElse IsDBNull(RD(0))) Then Ar_Assinatura = CType(RD(0), Byte()) RD.Close() End If End Select CONN.Close() Return 1 Catch ex As Exception If CONN.State = 1 Then CONN.Close() Psr_Erro = ex.ToString Return -1 End Try End Function End Class
MARIANO1776
- Editado Mariano1776 domingo, 15 de abril de 2018 23:18
- Sugerido como Resposta Lucio Rogerio SPBanned segunda-feira, 16 de abril de 2018 12:18
- Marcado como Resposta Filipe B CastroModerator quarta-feira, 2 de maio de 2018 21:37