如何将mp3歌曲插入数据库访问 [英] how to insert a mp3 song to database acces
问题描述
我是来自印度尼西亚国家的关键词,如何将带有folderbrowserdialog或openfolder组件的mp3歌曲插入带有vb 2010的目录文件夹中的数据库访问2007.
抱歉,我的英文很丑陋,谢谢,谢谢
I'm keysia from Indonesia Country, how to insert a mp3 song with folderbrowserdialog or openfolder component into database acces 2007 on directory folder with vb 2010.
Sorry my english is ugly and bad,thanks
推荐答案
Hi Keysia,
Hi Keysia,
如果你想将MP3文件插入Access DataBase,首先需要在Access中创建一个DataBase,我创建一个这样的数据库:
If you want to insert MP3 file into Access DataBase, you firstly need to create one DataBase in the Access, I create a database like this:
然后,请看下面的代码,我在表单中添加两个按钮,一个OpenfileDialog,一个Textbox。
Then, please see the following code, I add two button, one OpenfileDialog, one Textbox in the form.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim file As New FileStream(TextBox1.Text, FileMode.Open)
Using br As New BinaryReader(file)
Dim bytes As Byte() = br.ReadBytes(CInt(file.Length))
Dim str As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\DataBase1.accdb;Persist Security Info=False;"
Dim sql As String = "Insert into Test1(Name,ContentType,Data) values(@Name,@ContentType,@Data)"
Using conn As New OleDbConnection(str)
conn.Open()
Using cmd As New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("@Name", TextBox1.Text)
cmd.Parameters.AddWithValue("@ContentType", "audio/mpeg3")
cmd.Parameters.AddWithValue("@Data", bytes)
cmd.ExecuteNonQuery()
End Using
conn.Close()
End Using
End Using
End Sub
Private Sub FrmsaveMP3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub
最好的问候,
Cherry
这篇关于如何将mp3歌曲插入数据库访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!