If timeCounter = 1 And stat = "ACTIVE" Then
stat_in = "IN"
Using SQLConnection As New MySqlConnection(ServerString)
Using command As New MySqlCommand()
With command
.CommandText = "INSERT into time_table(id,student_id,tag,date,time,status) VALUES(@id,@student_id,@tag,@date,@time,@status); UPDATE rfid_stud SET timeCounter = 2 WHERE tag = '" & txtReceived.Text & "'"
.Connection = SQLConnection
.CommandType = CommandType.Text
.Parameters.AddWithValue("@id", idnum)
.Parameters.AddWithValue("@student_id", txtStudNo.Text)
.Parameters.AddWithValue("@tag", txtReceived.Text)
.Parameters.AddWithValue("@date", txtDate.Text)
.Parameters.AddWithValue("@time", txtTime.Text)
.Parameters.AddWithValue("@status", stat_in)
End With
Try
SQLConnection.Open()
command.ExecuteNonQuery()
Catch ex As Exception
Finally
SQLConnection.Close()
End Try
End Using
End Using
ElseIf timeCounter > 1 And stat = "ACTIVE" Then
stat_in = "OUT"
Using SQLConnection As New MySqlConnection(ServerString)
Using command As New MySqlCommand()
With command
.CommandText = "INSERT into time_table(id,student_id,tag,date,time,status) VALUES(@id,@student_id,@tag,@date,@time,@status); UPDATE rfid_stud SET timeCounter = 1 WHERE tag = '" & txtReceived.Text & "'"
.Connection = SQLConnection
.CommandType = CommandType.Text
.Parameters.AddWithValue("@id", idnum)
.Parameters.AddWithValue("@student_id", txtStudNo.Text)
.Parameters.AddWithValue("@tag", txtReceived.Text)
.Parameters.AddWithValue("@date", txtDate.Text)
.Parameters.AddWithValue("@time", txtTime.Text)
.Parameters.AddWithValue("@status", stat_in)
End With
Try
SQLConnection.Open()
command.ExecuteNonQuery()
Catch ex As Exception
Finally
SQLConnection.Close()
End Try
End Using
End Using
Else
MsgBox("RFID Card is INACTIVE! Please Contact System Administrator for assisstance.", vbExclamation, "Warning!")
End If
For i = 0 To (grid.Rows.Count - 1)
stringfix = grid.Rows.Item(i).Cells(0).Value
string1 = Microsoft.VisualBasic.Mid(stringfix, 1, 12)
string2 = Microsoft.VisualBasic.Mid(stringfix, 2, 12)
If string1 = string2 Then
newtag = False
Exit For
Else
newtag = True
End If
Next
If newtag = True And stat = "ACTIVE" Then
Dim dr As Integer
dr = grid.Rows.Add()
grid.Rows.Item(dr).Cells.Item(0).Value = txtReceived.Text
grid.Rows.Item(dr).Cells(1).Value = txtStudNo.Text
grid.Rows.Item(dr).Cells(2).Value = txtFname.Text
grid.Rows.Item(dr).Cells(3).Value = txtLname.Text
grid.Rows.Item(dr).Cells.Item(4).Value = txtDate.Text + " at " + txtTime.Text
If stat_in = "IN" Then
grid.Rows.Item(dr).Cells(5).Style.BackColor = Color.Green
grid.Rows.Item(dr).Cells(5).Style.ForeColor = Color.White
grid.Rows.Item(dr).Cells.Item(5).Value = stat_in
ElseIf stat_in = "OUT" Then
grid.Rows.Item(dr).Cells(5).Style.BackColor = Color.Red
grid.Rows.Item(dr).Cells(5).Style.ForeColor = Color.White
grid.Rows.Item(dr).Cells.Item(5).Value = stat_in
End If
End If
I have a warning on "If stat_in = IN". The main warning is the "stat_in" The same code runs on my pc without warning, but when I transfer my system to my laptop it shows 2 warnings. The program runs on my pc perfectly. Warnings are Warning BC42104 Variable 'stat_in' is used before it has been assigned a value. A null reference exception could result at runtime and the other one is variable "stat_in" is used before it has been assigned a value. a null exception could result at runtime. Desktop = windows 10, Laptop = windows, 7. I also tried it on a windows 10 laptop. Its not working too. Same version of Visual Studio. Visual Studio 2015 community. Im thinking of frameworks? Please help me. Im a beginner in coding vb.net.
Aucun commentaire:
Enregistrer un commentaire