使用vb.net将视频添加到Access数据库

时间:2018-04-25 22:28:07

标签: vb.net ms-access

我想知道如何使用visual.net在访问数据库中添加视频文件?

我知道如何使用ole对象在访问中添加视频,但是,我希望通过vb.net的表单来完成此操作

以下是我用于将图像添加到数据库的代码:

 Private Sub btn_Adicionar_Click(sender As System.Object, e As System.EventArgs) Handles btnIncluir.Click
    Dim cn As New OleDb.OleDbConnection
    'cn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" &  Application.StartupPath & "\Escola.mdb"
    cn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=D:\Documentos\Escola1.mdb"
    Try
        cn.Open()

        Dim arrImagem() As Byte
        Dim strImagem As String
        Dim ms As New IO.MemoryStream

        '
        If Not IsNothing(Me.picFoto.Image) Then
            Me.picFoto.Image.Save(ms, Me.picFoto.Image.RawFormat)
            arrImagem = ms.GetBuffer
            strImagem = "?"
        Else
            arrImagem = Nothing
            strImagem = "NULL"
        End If
        '------------------------<...>---------------

        Dim arrImagem2() As Byte
        Dim strImagem2 As String
        Dim ms2 As New IO.MemoryStream

        '
        If Not IsNothing(Me.PictureBox1.Image) Then
            Me.PictureBox1.Image.Save(ms2, Me.PictureBox1.Image.RawFormat)
            arrImagem2 = ms2.GetBuffer
            strImagem2 = "?"
        Else
            arrImagem2 = Nothing
            strImagem2 = "NULL"
        End If



        Dim myCmd As New OleDb.OleDbCommand
        myCmd.Connection = cn
        myCmd.CommandText = "INSERT INTO Alunos(nome, imagem, imagem2) " & _
                            " VALUES(?," & strImagem & "," & strImagem2 & ")"

        myCmd.Parameters.AddWithValue (New OleDb.OleDbParameter("@nome", Convert .ToString (Row ))


        If strImagem = "?" Then
            myCmd.Parameters.Add(strImagem, OleDb.OleDbType.Binary).Value = arrImagem
        End If

        If strImagem2 = "?" Then
            myCmd.Parameters.Add(strImagem2, OleDb.OleDbType.Binary).Value = arrImagem2
        End If


        myCmd.ExecuteNonQuery()
        MsgBox("Dados Salvos com sucesso!")
    Catch ex As Exception
        MsgBox("Erro" & ex.Message, MsgBoxStyle.Information)
    Finally
        cn.Close()
    End Try


    CarregaDados()
End Sub

我用来导入要在访问数据库中添加的图像的方法是:

 Private Sub label_link_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lnkProcurar.LinkClicked
    If Me.ofdImagem.ShowDialog = 1 Then
        Me.PictureBox1.Image = System.Drawing.Image.FromFile(Me.ofdImagem.FileName)
    Else
        Me.PictureBox1.Image = System.Drawing.Image.FromFile(Application.StartupPath & "/semfoto.jpg")
    End If
End Sub

现在我正在寻找一种通过vb.net在访问数据库中保存视频的方法。换句话说,一种允许通过vb.net表单在访问数据库中添加视频的方法

那些能帮助我的人......谢谢!!!

0 个答案:

没有答案