这是我的代码
Dim Cmd As New OleDbCommand
Dim strsql As String
Try
Dim fsreader As New FileStream(OpenFile.FileName, FileMode.Open, FileAccess.Read)
Dim breader As New BinaryReader(fsreader)
Dim imgbuffer(fsreader.Length) As Byte
breader.Read(imgbuffer, 0, fsreader.Length)
fsreader.Close()
strsql = "UPDATE AccResult SET (PicFile, PicName) Values (@pfile, @pname) WHERE StudNo = '" & Form1.sNo.Text & "'"
Cmd = New OleDbCommand(strsql, con)
Cmd.Parameters.AddWithValue("@pfile", txtSave.Text)
Cmd.Parameters.AddWithValue("@pname", imgbuffer)
Cmd.ExecuteNonQuery()
Cmd.Dispose()
Catch ex As Exception
End Try
请帮助我如何在数据库中保存图片时更新学生数据。即时通讯使用VB.NET。谢谢。
答案 0 :(得分:0)
看起来像是逻辑上的简单错误-您的文件名与文件内容相反
Cmd.Parameters.AddWithValue("@pfile", txtSave.Text)
Cmd.Parameters.AddWithValue("@pname", imgbuffer)
应该是
Cmd.Parameters.AddWithValue("@pfile", imgbuffer)
Cmd.Parameters.AddWithValue("@pname", txtSave.Text)