显示以前在 Picturebox 中扫描或检索的图像
Displaying a Image previous scanned or retrieved in Picturebox
我只是想为我的 RFID 考勤系统项目寻求帮助。应扫描 RFID 标签以从数据库中检索信息和图像 mysql。第一个学生将扫描他的 RFID 标签以在 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)
我只是想为我的 RFID 考勤系统项目寻求帮助。应扫描 RFID 标签以从数据库中检索信息和图像 mysql。第一个学生将扫描他的 RFID 标签以在 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)