显示先前在Picturebox中扫描或检索的图像 [英] Displaying a Image previous scanned or retrieved in Picturebox
问题描述
我只希望对我的RFID考勤系统项目有所帮助.应该扫描RFID标签以从数据库mysql检索信息和图像.第一位学生将扫描他的RFID标签以在picturebox1中显示他的照片,而另一位学生扫描时,picturebox1将被更新为新的学生照片和数据,并且先前的照片在所显示的picturebox2上.这里的问题是如何显示以前的照片学生的形象.仅图像,不包含数据.
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.
我有2个图片框
Picturebox1适用于扫描的新学生 Picturebox2适用于上一个或在新版本之前扫描的学生.
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
这是我的代码
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
推荐答案
很简单,您可以使用按钮显示上一张图片:
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)
这篇关于显示先前在Picturebox中扫描或检索的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!