我的代码有关将图像保存到mysql数据库的问题。有谁可以帮助我吗?
select to_date(
to_char(systimestamp,'dd-mon-yy hh:mi:ss PM')
, 'dd-mon-yy hh:mi:ss PM')
from dual;
这是我保存按钮的代码
Sub newstud()
If cbCard.Checked = True Then
card = "COMPLETE"
End If
If cbBirthCert.Checked = True Then
birthcert = "COMPLETE"
End If
If cbForm.Checked = True Then
form = "COMPLETE"
End If
If cbGMoral.Checked = True Then
gmoral = "COMPLETE"
End If
If picStr = vbNullString Then
picImage.Image.Save(".png", Imaging.ImageFormat.Png)
picStr = Application.StartupPath + (".\noimage.png")
End If
IMG = (Nothing)
IMG = Image.FromFile(picStr)
MyStream = New MemoryStream
IMG.Save(MyStream, Imaging.ImageFormat.Png)
Dim con As New MySqlConnection(conStr)
con.Open()
Try
Dim cmd As New MySqlCommand("insert into tbregistration(StudName,StudBday,StudGender,Address,DadName,DadBday,DadOccupation,MomName,MomBday,MomOccupation,Contact,LastSchool,Card,Form137,BirthCertificate,GoodMoral,Image)values('" & txtStudName.Text & "','" & dtpBirthday.Text & "','" & cmbGender.Text & "','" & txtAddress.Text & "','" & txtDadName.Text & "','" & dtpDadBday.Text & "','" & txtDadOccu.Text & "','" & txtMomName.Text & "','" & dtpMomBday.Text & "','" & txtMomOccu.Text & "','" & txtContact.Text & "','" & txtLastSchool.Text & "','" & card & "','" & form & "','" & birthcert & "','" & gmoral & "',@img,'"")", con)
cmd.Parameters.AddWithValue("@img", MySqlDbType.VarBinary).Value = MyStream.GetBuffer
cmd.ExecuteNonQuery()
cmd.Dispose()
MyStream.Dispose()
MyStream = Nothing
MsgBox("Admission done successfully", , "Admission")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
这是针对浏览图片按钮的。请帮我。非常感谢你
答案 0 :(得分:0)
你的意思是写:
Dim cmd As New MySqlCommand("insert into tbregistration(StudName,StudBday,StudGender,Address,DadName,DadBday,DadOccupation,MomName,MomBday,MomOccupation,Contact,LastSchool,Card,Form137,BirthCertificate,GoodMoral,Image)values('" & txtStudName.Text & "','" & dtpBirthday.Text & "','" & cmbGender.Text & "','" & txtAddress.Text & "','" & txtDadName.Text & "','" & dtpDadBday.Text & "','" & txtDadOccu.Text & "','" & txtMomName.Text & "','" & dtpMomBday.Text & "','" & txtMomOccu.Text & "','" & txtContact.Text & "','" & txtLastSchool.Text & "','" & card & "','" & form & "','" & birthcert & "','" & gmoral & "',@img,'"")", con)
cmd.Parameters.AddWithValue("@img", SqlDbType.VarBinary).Value = MyStream.GetBuffer
cmd.ExecuteNonQuery()
请注意第2行从MySqlDbType
到SqlDbType