我尝试保存"路径"在MYSQL数据库,但我收到错误
the datatype of photo is BLOB
数据库是imageupload
桌子是学生
希望有人可以帮我修复我的错误并命令保存数据库的路径
感谢我们更多的力量!
我的错误是
"The connection cannot be used to perform this operation. It is either closed or invalid in this context."
我在模块中的连接
Module Module1
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Sub konek()
With cn
.ConnectionString = "DRIVER={MY SQL ODBC 5.1 driver};SERVER=localhost;PWD=;UID=root;database=imageupload"
End With
End Sub
End Module
=============================================== =======================
我在Visual Basic 2010中的表单
Public Class Form1
Private Sub btnbrowsepic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowsepic.Click
OpenFileDialog1.FileName = ""
With OpenFileDialog1
.InitialDirectory = "C:\"
.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
.FilterIndex = 2
End With
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
With PictureBox1
.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.StretchImage
End With
End If
Me.lblpath.Text = Me.OpenFileDialog1.FileName.ToString
End Sub
Private Sub btnsavepic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavepic.Click
rs = New ADODB.Recordset
rs.Open("select * from student", cn, 3, 3)----- error is here when i save the path on my database
With rs
.AddNew()
.Fields("photo").Value = "" & lblpath.Text
.Update()
MsgBox("Data has been saved")
End With
End Sub
End Class