1,105,546 Community Members


Member Avatar
Newbie Poster
13 posts since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

Private Sub Load_Faculty()

        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
        sSQL = "SELECT b.FacultyID, b.Image, b.Course, a.Course"
        sSQL = sSQL & " FROM studentsrecords as a left join faculty as b "
        sSQL = sSQL & " on a.ID = b.FacultyID WHERE(a.Course = @Course) order by a.Course"

        con = New OleDbConnection(Get_Constring)
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        cmd.CommandText = sSQL
        ' cmd.Parameters.Add("@EvaluationID", OleDbType.DBDate).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
                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
    End Try
End Sub

i want to it ti read datas from the database if the system see the course it will load all teachers that is teaching within the course

Member Avatar
Junior Poster
139 posts since May 2012
Reputation Points: 49 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 6 [?]

For starters
In your Select Query you will need to add a Parameter for @Course.

            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = sSQL
            cmd.Parameters.AddWithValue("@Course",value of Course)

I also wouldn't open the connection until you have the Command Initialized but thats just me.

Member Avatar
Reverend Jim
Noli mentula
5,460 posts since Aug 2010
Reputation Points: 761 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]

A shorter way of coding that would be to reference the controls dynamically as

Dim pbx As PictureBox = Me.Controls("PictureBox" & dr("Course"))
pbx.Tag = dr("FacultyID")
pbx.Image = System.Drawing.Image.FromStream(myMS)

That replaces the entire select-case block with three lines of code.

Member Avatar
Junior Poster
197 posts since Dec 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 2 [?]

Mmm why don't you make it simple by making a folder that will contain all your pictures that will be used and then on your database just save there the directory address to prevent lot of coding for instance if you want to replace the image. saving to file will also prevent the future freezing on a slow computer memory.

This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article