我正在尝试通过打开OpenFileDiologue将文件名和文件路径存储到数据库中。这是我的代码 注意:DB已连接。正确显示datagridview和数据库上的数据是使用名为database1.accdb的ms访问创建的。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim showdialog1 As New OpenFileDialog
showdialog1.Filter = "Supported Video Files. | *.mp4; *.avi; *.wmv; *.mpg; *.mpeg; *.mov; *.webm; *.flv; *.mkv"
showdialog1.Title = "Add Supported Video Files."
If showdialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = showdialog1.FileName
Else
Exit Sub
End If
End Sub
这是我设计的照片。这将有助于你了解我
Click to View the pic
帮助我将文件名和文件路径存储到数据库中。希望我能得到最简单的方法。
答案 0 :(得分:0)
很简单:
Public sub Button1_Click
'your connection string
connection.open
Dim cmd as new Oledbcommand("Insert into
[tablename](columnname) values (@mycolumn)",yourconnectionstringname)
If openfiledialog1.dialogresult=dialogresult.ok then
cmd.parametres.add("@mycolumn",sqldbtype.varchar).value=openfiledialog1.filename
cmd.executenonquery()
connection.close
我希望这有助于实现目标