0% found this document useful (0 votes)
33 views2 pages

Msaccess & Ado

The document describes code for uploading and viewing images from an MS Access database. It includes: 1) Creating an MS Access database with a table to store student ID, name, and photo data. 2) Designing a form to accept input for ID, name, and photo upload into a picture box, then adding the record to the database. 3) On a search button click, querying the database for a record matching the input ID, retrieving the associated name and photo, and displaying them.

Uploaded by

nanisanju
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Msaccess & Ado

The document describes code for uploading and viewing images from an MS Access database. It includes: 1) Creating an MS Access database with a table to store student ID, name, and photo data. 2) Designing a form to accept input for ID, name, and photo upload into a picture box, then adding the record to the database. 3) On a search button click, querying the database for a record matching the input ID, retrieving the associated name and photo, and displaying them.

Uploaded by

nanisanju
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

UPLOAD & VIEW IMAGES FROM MSACCES DATABASE 1.

The following code upload image into ms access database when ADD button is clicked and searches for the image when SEARCH button is clicked 2. CREATE ms acces database student as following stud(id --Number, name Text , photo OLEObject) 3. Design a form that accepts Id ,name and photo to be uploaded in to picture box and click ADD 4. Enter ID and click SEARCH to get the saved result back

UPLOAD LINKLABEL CLICK EVENT Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked OpenFileDialog1.ShowDialog() PictureBox1.ImageLocation = OpenFileDialog1.FileName End Sub ADD BUTTON CLICK EVENT Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\mkrao\Desktop\student.mdb") con.Open() Dim arrImage() As Byte Dim strImage As String Dim myMs As New IO.MemoryStream Me.PictureBox1.Image.Save(myMs, Me.PictureBox1.Image.RawFormat)

arrImage = myMs.GetBuffer strImage = "?" Dim myCmd As New OleDb.OleDbCommand myCmd.Connection = con myCmd.CommandText = "INSERT INTO stud VALUES(" & TextBox1.Text & ",' " & TextBox2.Text & "'," & strImage & ")" If strImage = "?" Then myCmd.Parameters.Add(strImage, OleDb.OleDbType.Binary).Value = arrImage End If MsgBox("Data save successfully!") myCmd.ExecuteNonQuery() con.Close() End Sub SEARCH BUTTON CLICK EVENT Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\mkrao\Desktop\student.mdb") cn.Open() Dim arrImage() As Byte Dim myMS As New IO.MemoryStream Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM stud WHERE id=" & TextBox1.Text, cn) Dim dt As New DataTable da.Fill(dt) Me.TextBox2.Text = dt.Rows(0).Item("name") & "" arrImage = dt.Rows(0).Item("photo") For Each ar As Byte In arrImage myMS.WriteByte(ar) Next Me.PictureBox1.Image = System.Drawing.Image.FromStream(myMS) Me.Button1.Enabled = False cn.Close() End Sub

You might also like