Hye all. I need some help. Iam using vb.net 2010 and MS Acsess 2013. I have problem when retrieve multiple rows from database to datagridview. All rows have the same identification number(RFID Card No.).I want to record how many times the card had scan. Please help me here. Thanks for advance.
Public Sub updateTextBox()
data = data + myComPort.ReadExisting()
If Len(data) = 12 Then
Dim i As Integer
Dim newdata As Boolean = True
For i = 0 To (grid.Rows.Count - 1)
If grid.Rows.Item(i).Cells(0).Value = Microsoft.VisualBasic.Mid(data, 6, 6) Then
newdata = False
Exit For
Else
newdata = True
End If
Next
If newdata = True Then
Dim gr As Integer
gr = grid.Rows.Add()
grid.Rows.Item(gr).Cells.Item(0).Value = Microsoft.VisualBasic.Mid(data, 6, 6)
grid.Rows.Item(gr).Cells.Item(3).Value = DateString() + " " + TimeString()
Notify.BalloonTipTitle = "New Tag"
Notify.BalloonTipText = Microsoft.VisualBasic.Mid(data, 6, 6)
Notify.ShowBalloonTip(2000)
Try
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Afeeq\Documents\Database2.accdb")
cn.Open()
str = "insert into table1 (Tag, L_Scan) values('" & grid.Rows.Item(grid.RowCount() - 1).Cells.Item(0).Value & " ','" & grid.Rows.Item(grid.RowCount() - 1).Cells.Item(3).Value & "')"
'string stores the command and CInt is used to convert number to string
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
'MessageBox.Show(icount)
'displays number of records inserted
Catch e2 As Exception
MessageBox.Show(e2.ToString)
End Try
cn.Close()
Else
grid.Rows.Item(i).Cells.Item(3).Value = DateString() + " " + TimeString()
grid.Rows.Item(i).Selected = True
Notify.BalloonTipTitle = "Tag Scanned"
Notify.BalloonTipText = Microsoft.VisualBasic.Mid(data, 6, 6)
Notify.ShowBalloonTip(2000)
Try
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Afeeq\Documents\Database2.accdb")
cn.Open()
str = "update table1 SET L_Scan = '" & grid.Rows.Item(i).Cells.Item(3).Value & "' where Tag = '" & grid.Rows.Item(i).Cells.Item(0).Value & "'"
'string stores the command and CInt is used to convert number to string
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
'MessageBox.Show(icount)
'displays number of records inserted
Catch e2 As Exception
MessageBox.Show(e2.ToString)
End Try
cn.Close()
End If
myComPort.DtrEnable = False
RadioButton1.Enabled = False
RadioButton2.Checked = True
If CheckBox1.Checked = True Then
Beep()
End If
Dim timeOut As DateTimeOffset = Now.AddMilliseconds(1500)
Do
Application.DoEvents()
Loop Until Now > timeOut
data = myComPort.ReadExisting()
myComPort.DiscardInBuffer()
data = ""
myComPort.DtrEnable = True
RadioButton1.Enabled = True
RadioButton1.Checked = True
End If
End Sub