好的,所以我试图上传到数据库,选择文件的名称、类型、大小(以字节为单位)以及它自己到数据库的文件。到目前为止,除了将自己的文件上传到数据库之外,我一切顺利。所以我的问题是我如何将文件本身上传到数据库
这是我已经拥有的代码
Dim s = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName)
MessageBox.Show("File Name:" & s.Name)
MessageBox.Show("File Type:" & s.Extension)
MessageBox.Show("File Size (Bytes):" & s.Length)
Try
Dim cmd As New MySqlCommand
Dim insertStatment As String = "INSERT INTO upload (name, type, size) VALUES
(@name, @type, @size)"
cmd = New MySqlCommand(insertStatment, db_con)
cmd.Parameters.AddWithValue("@name", s.Name)
cmd.Parameters.AddWithValue("@type", s.Extension)
cmd.Parameters.AddWithValue("@size", s.Length)
cmd.ExecuteNonQuery()
MessageBox.Show("ok")
db_con.Close()
Catch ex As Exception
MessageBox.Show("Something went wrong, please try again")
db_con.Close()
End Try