我正在尝试将图像从文件夹保存到访问数据库。这是我在保存中的代码。
Dim FileDialog As New OpenFileDialog
Try
Dim sqlconn As New OleDb.OleDbConnection
Dim sqlquery As New OleDb.OleDbCommand
Dim connString As String
Dim Stream As FileStream
Dim Reader As StreamReader
Stream = New FileStream(tbpath.Text, FileMode.Open, FileAccess.Read)
Reader = New StreamReader(Stream)
Dim ImagePath(Stream.Length - 1) As Byte
Stream.Read(ImagePath, 0, Stream.Length - 1)
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= \\10.227.31.22\CPS$\Computer Profile System.mdb"
sqlconn.ConnectionString = connString
sqlquery.Connection = sqlconn
sqlconn.Open()
sqlquery.CommandText = "INSERT INTO TempLog(PIC, ControlNumber, Department, DateDelivered, Warranty,ImagePath)VALUES(@pic, @controlnumber, @department, @datedelivered, @warranty, @ImagePath)"
sqlquery.Parameters.AddWithValue("@pic", tbname.Text)
sqlquery.Parameters.AddWithValue("@controlnumber", tbcontrol.Text)
sqlquery.Parameters.AddWithValue("@department", tbdepartment.Text)
sqlquery.Parameters.AddWithValue("@datedelivered", tbdatedelivered.Text)
sqlquery.Parameters.AddWithValue("@warranty", tbwarranty.Text)
sqlquery.Parameters.AddWithValue("@ImagePath", ImagePath)
sqlquery.ExecuteNonQuery()
lblpath.Content = FileDialog.FileName(tbpath.Text.Trim) & " Stored Successfully...."
If tbname.Text = "" Then
MessageBox.Show("PLEASE ENTER NAME.")
ElseIf tbcontrol.Text = "" Then
MessageBox.Show("PLEASE ENTER CONTROL NUMBER.")
ElseIf tbname.Text = "" Then
MessageBox.Show("PLEASE ENTER NAME.")
ElseIf tbcontrol.Text = "" Then
MessageBox.Show("PLEASE ENTER CONTROL NUMBER.")
ElseIf tbname.Text = "" Then
MessageBox.Show("PLEASE ENTER NAME.")
ElseIf tbcontrol.Text = "" Then
MessageBox.Show("PLEASE ENTER CONTROL NUMBER.")
Else
MessageBox.Show("RECORD SUCCESSFULLY.")
End If
sqlquery.ExecuteNonQuery()
sqlconn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function FileName(ByVal Pth As String) As String
Dim SlashPosition As Integer = Pth.LastIndexOf("\")
Dim Flname As String = Pth.Substring(SlashPosition + 1)
Return Flname
End Function
错误说"从字符串转换"图像路径"输入'整数'无效"。请帮忙。我被困在这里一个星期。