Displaying a Image previous scanned or retrieved in Picturebox

久未见 提交于 2019-12-11 16:18:14

问题


I just want some help for my project which is RFID attendance system. The RFID tag should be scan to retrieve the information and Image from the database mysql. The first student will scan his RFID tag to display his picture in picturebox1 and when another student scan the picturebox1 will be updated to a new student picture and data and the previous one is on the picturebox2 displayed The issue here is how can I display the previous Image of the student. Just only the Image ,the data is not included.

I have a 2 picturebox

Picturebox1 is for new student scanned Picturebox2 is for the previous one or the student who scan before the new.

Thank you guys ..Any suggestions and comment will totally appreciated

Here is my code

Private Sub studtag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles studtag.TextChanged
    If studtag.TextLength = 8 Then


        con = New MySqlConnection
        con.ConnectionString = "server=localhost;userid=root;password=1234;database=dat"
        Dim query As String

        query = "select * from dat.students"
        cmd = New MySqlCommand(query, con)



        Dim table As New DataTable

        Try
            con.Open()
            'Gets or sets an SQL statement or stored procedure used to select records in the database.
            With cmd
                .Connection = con
                .CommandText = "SELECT * from students where `studtags`='" & studtag.Text & "';"
            End With
            da.SelectCommand = cmd
            da.Fill(table)
            'it gets the data from specific column and fill it into textbox
            studtag.Text = table.Rows(0).Item(0)
            idno.Text = table.Rows(0).Item(1)
            lastxt.Text = table.Rows(0).Item(2)
            firstxt.Text = table.Rows(0).Item(3)
            middletxt.Text = table.Rows(0).Item(4)
            dob.Text = table.Rows(0).Item(6)

            crsetxt.Text = table.Rows(0).Item(10)

            tagtxt.Text = studtag.Text
            timein.Text = times.Text

            dr = cmd.ExecuteReader()
            dr.Read()

            If dob.Text = datenow.Text Then
                greet.Text = "Happy Birthday To You"

            End If



            Dim img() As Byte = CType(dr("studpic"), Byte())


            Using ms As New IO.MemoryStream(img)
                PictureBox1.Image = Image.FromStream(ms)

            End Using
            insert()
            loadtable()

        Catch ex As Exception
            Notenrolled.Show()
        Finally

            con.Dispose()
            con.Close()
        End Try

    End If

End Sub

Public Sub loadtable()

    con = New MySqlConnection
    con.ConnectionString = "server=localhost;userid=root;password=1234;database=dat"
    Dim SDA As New MySqlDataAdapter
    Dim dbDataset As New DataTable
    Dim bSource As New BindingSource


    Try

        con.Open()
        Dim query3 As String

        query3 = "select studtags,idno,lastxt,firstxt,middletxt,dob,log,timein,crse from dat.studlogs"
        cmd = New MySqlCommand(query3, con)
        SDA.SelectCommand = cmd
        SDA.Fill(dbDataset)
        bSource.DataSource = dbDataset
        DataGridView1.DataSource = bSource
        SDA.Update(dbDataset)
        DataGridView1.Sort(DataGridView1.Columns(8), System.ComponentModel.ListSortDirection.Ascending)
        If dbDataset.Rows.Count > 0 Then
            logins.Text = table2.Rows.Count.ToString()
        End If


        con.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        con.Dispose()
    End Try
End Sub

 Private Sub Students_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    loadtable()
    ''Date Now 
    Timer2.Start()


    Try
        DataGridView1.AllowUserToAddRows = False ' Disabled or hide (*) Symbol...

        DataGridView1.RowHeadersVisible = False 'To hide Left indicator..
        DataGridView1.DefaultCellStyle.SelectionBackColor = Color.SteelBlue  'Selection backcolor....
        DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGoldenrodYellow 'Alternating Backcolor.
        DataGridView1.AllowUserToResizeRows = False 'Disabled  row resize...
        DataGridView1.ReadOnly = True
        DataGridView1.MultiSelect = False
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView1.ShowRowErrors = False
        DataGridView1.ShowCellErrors = False


        table2.Columns.Add("Student Tag", Type.GetType("System.String"))
        table2.Columns.Add("Student ID", Type.GetType("System.Int32"))
        table2.Columns.Add("Last Name", Type.GetType("System.String"))
        table2.Columns.Add("First Name", Type.GetType("System.String"))
        table2.Columns.Add("Middle Name", Type.GetType("System.String"))

        table2.Columns.Add("Status", Type.GetType("System.String"))
        table2.Columns.Add("Birthday", Type.GetType("System.String"))
        table2.Columns.Add("Time in", Type.GetType("System.String"))
        table2.Columns.Add("Course/Sec", Type.GetType("System.String"))


    Catch ex As Exception

    End Try

回答1:


It's quiet easy,You can use a button to display the previous image :

  If datagridview1.CurrentRow.Index < datagridview1.Rows.Count Then
  datagridview1.Rows(datagridview1.SelectedRows(0).Index - 1).Selected 
             = True
 Dim pic As Byte()
 pic = datagridview1.CurrentRow.Cells(1).Value
 Dim ms As New MemoryStream(pic)
 pbox1.BackgroundImage = Image.FromStream(ms) 


来源:https://stackoverflow.com/questions/47420454/displaying-a-image-previous-scanned-or-retrieved-in-picturebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!