我是Visual Basic的初学者,我想提出一个学生注册申请,但由于无法将图像放入数据库而被困,可以共享必要的代码以将图像从vb放入Mysql数据库吗?我在互联网和stackoverflow帖子中进行了搜索,但我仍然听不懂。
这是我的代码
Public Class Form1
Private PathFile As String = Nothing
Dim sql As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call TampilTabel()
End Sub
Private Sub Back_Click(sender As Object, e As EventArgs) Handles Back.Click
Close()
End Sub
Sub TampilTabel()
Dim PT As String
Call BukaDB()
DS.Clear()
PT = "select *from tb_ekskul"
DA.SelectCommand = New Odbc.OdbcCommand(PT, koneksi)
DA.Fill(DS, "tb_ekskul")
DataGridView1.DataSource = DS.Tables("tb_ekskul")
End Sub
Sub BersihTextbox()
TextNIS.Text = ""
TextNama.Text = ""
TextJenkel.Text = ""
TextTempat.Text = ""
TextJurusan.Text = ""
TextTanggal.Text = ""
TextEkskul.Text = ""
TextAsal.Text = ""
TextNmgambar.Text = ""
Alamatgambar.Text = ""
pct_gambar.Image = Nothing
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
Dim PR As String
Call BukaDB()
PR = "insert into tb_ekskul values('" & TextNIS.Text & "','" & TextNama.Text & "','" & TextJenkel.Text & "','" & TextTempat.Text & "','" & TextTanggal.Text & "','" & TextJurusan.Text & "','" & TextAsal.Text & "','" & TextEkskul.Text & "')"
DA.InsertCommand = New Odbc.OdbcCommand(PR, koneksi)
DA.InsertCommand.ExecuteNonQuery()
Call TampilTabel()
Call BersihTextbox()
End Sub
Private Sub Choose_Click(sender As Object, e As EventArgs) Handles Choose.Click
On Error Resume Next
OpenFileDialog1.Filter = "JPG Files(*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|GIF Files(*.gif)|*.gif|PNG Files(*.png)|*.png|BMP Files(*.bmp)|*.bmp|TIFF Files(*.tiff)|*.tiff"
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
pct_gambar.SizeMode = PictureBoxSizeMode.StretchImage
pct_gambar.Image = New Bitmap(OpenFileDialog1.FileName)
Choose.Enabled = True
PathFile = OpenFileDialog1.FileName
TextNmgambar.Text = PathFile.Substring(PathFile.LastIndexOf("\") + 1)
Alamatgambar.Text = OpenFileDialog1.FileName
pct_gambar.Image = Image.FromFile(Alamatgambar.Text)
End If
End Sub End Class
对不起,英语不好