加载数据和图片会导致错误

时间:2013-09-18 14:40:06

标签: vb.net ms-access

如果学生课程是BSIT,我想加载所有教师,然后将所有BSIT学院加载到图片框

Dim con As New OleDbConnection
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Dim arrImage() As Byte
Dim myMS As New IO.MemoryStream
Dim sSQL As String = String.Empty
Try
  sSQL = "SELECT b.FacultyID, b.Image, b.Course, a.Course"
  sSQL = sSQL & " FROM studentsrecords as a left join facultynew as b "
  sSQL = sSQL & " on a.ID = b.FacultyID WHERE(a.Course = @Course) order by a.Course"

  con = New OleDbConnection(Get_Constring)
  con.Open()
  cmd.Connection = con
  cmd.CommandType = CommandType.Text
  cmd.CommandText = sSQL
  '  cmd.Parameters.Add("@EvaluationID", OleDbType.VarChar).Value

  dr = cmd.ExecuteReader
  If dr.HasRows Then
    While dr.Read
      If Not IsDBNull(dr("Image")) Then
        myMS = New IO.MemoryStream
        arrImage = dr("Image")
        For Each ar As Byte In arrImage
          myMS.WriteByte(ar)
        Next
      End If
      Select Case dr("Course")
        Case 1
          Me.pic1.Tag = dr("FacultyID")
          Me.pic1.Image = System.Drawing.Image.FromStream(myMS)
        Case 2
          Me.pic2.Tag = dr("FacultyID")
          Me.pic2.Image = System.Drawing.Image.FromStream(myMS)
        Case 3
          Me.pic3.Tag = dr("FacultyID")
          Me.pic3.Image = System.Drawing.Image.FromStream(myMS)
        Case 4
          Me.pic4.Tag = dr("FacultyID")
          Me.pic4.Image = System.Drawing.Image.FromStream(myMS)
        Case 5
          Me.pic5.Tag = dr("FacultyID")
          Me.pic5.Image = System.Drawing.Image.FromStream(myMS)
        Case 6
          Me.pic6.Tag = dr("FacultyID")
          Me.pic6.Image = System.Drawing.Image.FromStream(myMS)
        Case 7
          Me.pic7.Tag = dr("FacultyID")
          Me.pic7.Image = System.Drawing.Image.FromStream(myMS)
        Case 8
          Me.pic8.Tag = dr("FacultyID")
          Me.pic8.Image = System.Drawing.Image.FromStream(myMS)
        Case 9
          Me.pic9.Tag = dr("FacultyID")
          Me.pic9.Image = System.Drawing.Image.FromStream(myMS)
        Case 10
          Me.pic10.Tag = dr("FacultyID")
          Me.pic10.Image = System.Drawing.Image.FromStream(myMS)
      End Select
    End While
  End If

  Catch ex As Exception
    MsgBox(ErrorToString)
  Finally
    con.Close()
  End Try

1 个答案:

答案 0 :(得分:0)

尝试

cmd.Parameters.AddWithValue("@EvaluationID", ValueForParameter)

这是pic

Dim bm As Bitmap
arrImage() = dr.Item("Picture")
ms.Write(arrImage, 78, arrImage.Length - 78)
bm = New Bitmap(ms)

Select Case dr("Course")
    Case 1
      Me.pic1.Tag = dr("FacultyID")
      Me.pic1.Image = bm