需要帮助
尝试插入员工的图像(在EmployeeTable中)
Protected Sub ImageAddButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ImageAddButton.Click
Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString").ToString)
con.Open()
If EmployeeIDTextBox.Text = "" Then
MsgBox("Please Enter EmployeeID to Add Photo")
Else
Dim com As New SqlCommand("UPDATE EmployeeTable SET IMAGE = (@IM) where EmployeeID='" & EmployeeIDTextBox.Text & "'", con)
**Dim imageData As Byte() = File.ReadAllBytes(FileUpload1.FileName)**
com.Parameters.AddWithValue("@IM", imageData)
com.ExecuteNonQuery()
在**行中出错...帮助赞赏...
答案 0 :(得分:0)
将代码修改为如下所示:
Protected Sub ImageAddButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ImageAddButton.Click
Dim imageData as Byte() = New Byte(FileUpload1.FileContent.Length){}
FileUpload1.FileContent.Read(imageData, 0, Convert.ToInt32(FileUpload1.FileContent.Length))
Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString").ToString)
con.Open()
If EmployeeIDTextBox.Text = "" Then
MsgBox("Please Enter EmployeeID to Add Photo")
Else
Dim com As New SqlCommand("UPDATE EmployeeTable SET IMAGE = (@IM) where EmployeeID='" & EmployeeIDTextBox.Text & "'", con)
com.Parameters.AddWithValue("@IM", imageData)
com.ExecuteNonQuery()