0
美好的一天!我目前正在使用Access數據庫在VB.Net中構建一個學生管理信息系統。除此之外,所有內容都可以正常工作:從MS Access數據庫顯示圖片
顯示當前登錄用戶的圖片,從其「圖片」列中顯示。
所有文本字段顯示在根據登錄的當前用戶我的數據庫中分配的所有值這裏是我用來顯示用戶的信息代碼:
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
。但是如何?任何幫助將不勝感激。謝謝!
保存時需要將圖像轉換爲字節數組,然後在讀取記錄時將其轉換回來。 [這個答案](http://stackoverflow.com/q/217928/1070452)對C#(基本上是image-> memstream - > byte())是這樣做的。您還需要實現SQL參數以避免SQL注入攻擊。 – Plutonix
感謝您的回答。無論如何,我是否必須複製他/她的代碼並將其轉換爲vb? – Lezirhc
我會使用JPG作爲基礎而不是BMP - 它會導致較小的輸出。否則,您可以使用最後4行代碼來查看步驟(反向保存到數據庫)。這裏是一個VB版本:http://stackoverflow.com/a/6861581/1070452 – Plutonix