显示MS Access数据库中的图片

时间:2014-02-15 16:07:16

标签: vb.net ms-access picturebox

美好的一天!我目前正在使用Access数据库在VB.Net中构建学生管理信息系统。除了这一件外,所有事情都完美无缺:

从图片列中显示当前登录用户的图像。

所有文本字段都显示我的数据库中分配的所有值,具体取决于当前登录的用户。这是我显示用户信息的代码:

Dim cn As New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\Data\Db\Faculty.mdb;")
    Dim dr1 As OleDbDataReader
    Dim com As New OleDbCommand


    com.CommandText = "select [Username],[Fname],[Lname],[Mname],[NickName],[Birthday],[Adds],[City],[CounPC],[Gender],[Religion],[Citizenship],[Contact],[stats],[Fathername],[Mothername],[FMAddress],[CollCourse],[VocCourse],[ElemEd],[ElemGrad],[HighEd],[HighGrad],[CollegeEd],[CollegeGrad],[VocationalCourse],[Skills],[Company],[Company1],[Position],[Position1],[YrStart],[YrStart1] from Personal where Username = '" & mainForm.TSUname.Text & "'"
    com.Connection = cn
    If cn.State = ConnectionState.Closed Then cn.Open()

    ' Username
    Dim Username As OleDbParameter = New OleDbParameter("@Username", OleDbType.VarWChar, 50)
    Username.Value = mainForm.TSUname.Text.ToString
    com.Parameters.Add(Username)

    dr1 = com.ExecuteReader
    If dr1.Read Then
        If dr1(1) = My.Settings.CurrentUserName.ToString Then
            ' Personal Information
            tbFname.Text = dr1(1)
            tbLname.Text = dr1(2)
            tbMname.Text = dr1(3)
            lblNickname.Text = dr1(4) & "!"
            tbBday.Text = dr1(5)
            tbAdd.Text = dr1(6)
            tbCity.Text = dr1(7)
            tbCountry.Text = dr1(8)
            tbGender.Text = dr1(9)
            tbReligion.Text = dr1(10)
            tbCitizenship.Text = dr1(11)
            tbContact.Text = dr1(12)
            tbStatus.Text = dr1(13)
            ' Parents
            tbFather.Text = dr1(14)
            tbMother.Text = dr1(15)
            tbAddress.Text = dr1(16)
            'Educational Background
            tbCollCourse.Text = dr1(17)
            tbVocCourse.Text = dr1(18)
            tbElemEd.Text = dr1(19)
            tbElemGrad.Text = dr1(20)
            tbHSEd.Text = dr1(21)
            tbHSGrad.Text = dr1(22)
            tbCollED.Text = dr1(23)
            tbColGrad.Text = dr1(24)
            tbVocational.Text = dr1(25)
            tbSkill.Text = dr1(26)
            ' Employment Background
            tbCompany.Text = dr1(27)
            tbCompany1.Text = dr1(28)
            tbPosition.Text = dr1(29)
            tbPosition1.Text = dr1(30)
            tbStart.Text = dr1(31)
            tbStart1.Text = dr1(32)
        Else
            MessageBox.Show("Incorrect Input", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Else
        MessageBox.Show("UserID is Wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

我想将用户的图片放在我的PictureBox中。但是怎么样?任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

我跟随大多数人,只是将图像上传到特定目录,然后将其路径存储在我的数据库中。然后,每当我想要检索图像并将其分配给我的picturebox的imagePath属性时,我就会得到路径。