导入System.IO 导入MySql.Data.MySqlClient
公开课表格1 将Opfile设为新的OpenFileDialog 昏暗的full_file_name作为字符串 昏暗的文件名作为字符串 私有子Form1_Load(作为对象发送,作为EventArgs发送)处理MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
opfile.FileName = Nothing
TextBox1.Text = ""
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'Try
full_file_name = TextBox1.Text
full_file_name.Split("\")
filename = full_file_name.Last.ToString
Dim con As MySqlConnection = New MySqlConnection("server=localhost;User Id=root;password=root;database=sampledb")
Dim cmd As MySqlCommand = New MySqlCommand
cmd.Connection = con
cmd.CommandText = "insert into table1 (filename,[content]) values (@filename,@file)"
With cmd.Parameters
.AddWithValue("filename", filename)
.AddWithValue("file", MySqlDbType.VarBinary).Value = File.ReadAllBytes(TextBox1.Text)
End With
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("file saved")
TextBox1.Clear()
'Catch ex As Exception
'MsgBox(ex.Message)
'End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If opfile.ShowDialog = DialogResult.OK Then
TextBox1.Text = opfile.FileName
End If
End Sub
结束班级