将二进制数据表单数据库加载到vb net

时间:2013-10-12 02:50:37

标签: vb.net ms-access

我有两张桌子,教师和学生记录。 facultynew由字段FacultyID,FacultyFirstName,FacultyLastname,Course,Image,Level组成 而 学生记录包括IDNumber,名字,MiddleName,课程

我有1个文本框和图片框以及1个按钮

我的文本框已经正常运行。,。当我使用我的IDNumber登录时,它将显示IDnumber的路线。,。,它已经确定。,。,。,

我的问题是加载教师 如果我点击按钮 ex.txtbox = BSIT 然后在数据库中加载所有BSIT课程教师。,。,将图片加载到图片框中,。,保存到数据库中的图片。,。作为长二进制数据

如果学生的课程= BSIT然后加载教师在图片框上教BSIT的图像 我只是一个新手..,

我有一个代码,但我需要专家的帮助,。,。此代码不加载

Dim con As New OleDbConnection
Dim dr As OleDbDataReader
Dim arrImage() As Byte
Dim myMS As New IO.MemoryStream
Dim cmd As New OleDbCommand
Dim strcourse As String
Dim sSQL As String

Dim da As New OleDb.OleDbDataAdapter

' con = New OleDbConnection(Get_Constring)
' con.Open()

' strcourse = "select Course from facultynew where FacultyID"
' strcourse1 = "select Course from studentsrecords where IDNumber"

' da = New OleDb.OleDbDataAdapter(strcourse, con)
' da = New OleDb.OleDbDataAdapter(strcourse1, con)
' MsgBox("asdasd")

sSQL = "SELECT b.Course, b.Image, a.IDNumber"
sSQL = sSQL & " FROM studentsrecords as a left join facultynew as b"
sSQL = sSQL & " on a.Course = b.Course WHERE(b.FacultyLastName = @FacultyLastName) order by a.IDNumber"

con = New OleDbConnection(Get_Constring)
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = sSQL

cmd.Parameters.AddWithValue("@FacultyLastName", OleDbType.VarChar).Value = DBNull.Value
'cmd.Parameters.Add("@Course", OleDbType.BigInt).Value = ifacID
'cmd.Parameters.Add("@IDNumber", OleDbType.BigInt).Value = ieval

'= IIf(Len(Trim(Me.txtFacultyLastName.Text)) > 0, Me.txtFacultyLastName.Text, DBNull.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("IDNumber")
            Case 1
                Me.pic1.Tag = dr("b.Course")
                Me.pic1.Image = System.Drawing.Image.FromStream(myMS)
        End Select
    End While
End If

0 个答案:

没有答案