mysql - 显示以前在 Picturebox 中扫描或检索的图像

标签 mysql vb.net picturebox

我只是想为我的项目 RFID 考勤系统提供一些帮助。应扫描 RFID 标签以从数据库 mysql 中检索信息和图像。第一个学生将扫描他的 RFID 标签以在 picturebox1 中显示他的图片,当另一个学生扫描 picturebox1 时,picturebox1 将更新为新的学生图片和数据,而前一个学生将显示在 picturebox2 上。这里的问题是如何显示前一个学生学生的形象。仅包含图像,不包含数据。

我有一个 2 图片框

Picturebox1 供新生扫描 Picturebox2 适合上一张或在新一张之前扫描的学生。

谢谢你们..任何建议和评论将不胜感激

这是我的代码

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

最佳答案

这很简单,您可以使用按钮来显示上一张图像:

  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) 

关于mysql - 显示以前在 Picturebox 中扫描或检索的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47420454/

相关文章:

mysql - 这段代码一直给我错误,我看不到它可能在哪里

c# - 面板中的移动图片框

mysql - 将两个案例查询合并为一个

php - PDO登录页面,当用户连接时选择指定行并对其执行某些操作

mysql - 如何根据查询插入多行?

c# - 图标存在于系统托盘中?

vb.net - WinForms TableLayoutPanel ComboBox 无法正确调整大小

vb.net - 无法检测 Enter 键的 KeyPress 事件

c# - 如何永久显示放置的图像

c# - 在PictureBox中锁定图像文件