2

在这里需要小帮助

m 试图插入员工的图像(在 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()

在 ** 中的行出现错误......感谢帮助......

4

1 回答 1

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()
于 2013-03-02T12:07:41.990 回答