Student attendance time in time out - vb.net

i made a student attendance system using barcode scanner and its already working the time in time out works well but my problem is this after the student scan his/her barcode for time out the next time he/she scan his/her barcode the remarks should be time in but my code only sticks with a time out remarks.
this is my code for time in time out
Dim check As Boolean
Call connect()
Dim cmdd As New MySqlCommand("Select Count(*) from attendance_for_student WHERE Remarks = 'IN' ", dbconn)
Dim i As Integer = cmdd.ExecuteScalar()
cmdd = Nothing
dbconn.Close()
TextBox1 .Text = i
If student.Text = "" Then
MsgBox("Scan Your Code!", MsgBoxStyle.Critical)
Else
Call connect()
sql = "SELECT * FROM student WHERE Sbarcode='" & student.Text & "'"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader
Do While dbread.Read
Dim id As String = student.Text
Dim folder As String = "c:\jpnhs\"
Dim filename As String = System.IO.Path.Combine(folder, id & ".bmp")
PictureBox1.Image = Image.FromFile(filename)
FULLNAME.Text = dbread.Item(1).ToString & " " & dbread.Item(2).ToString & " " & dbread.Item(3).ToString
Loop
dbread.Close()
dbconn.Close()
End If
If Len(student.Text) = 8 Then
Call connect()
check = False
sql = "SELECT * FROM attendance_for_student WHERE Sbarcode = '" & student.Text & "' AND (remarks <>'IN' OR remarks <>'OUT')"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader
Do While dbread.Read
check = True
Loop
dbread.Close()
dbconn.Close()
If check = False Then
Call connect()
sql = "INSERT INTO attendance_for_student(Sbarcode,Time,Date,remarks) VALUES ('" & student.Text & "','" & LBLTime.Text & "','" & LBLDate.Text & "','IN')"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
dbconn.Close()
Search_Code()
Else
Call connect()
sql = "INSERT INTO attendance_for_student(Sbarcode,Time,Date,remarks) VALUES ('" & student.Text & "','" & LBLTime.Text & "','" & LBLDate.Text & "','OUT')"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
dbconn.Close()
Search_Code()
End If
End If

Related

Shows Error Conversion from String to type Double is not Valid, Input String is not in correct Format

Following are my codes Pls Help me
I found this error on updating the Table
Private Sub UpdateInventory()
Dim connectionString As String = ConfigurationManager.ConnectionStrings("MainConString").ConnectionString
Dim con As New SqlConnection(connectionString)
Dim Query1 As String
Try
Dim Result As DialogResult
Result = MessageBox.Show(" Update this Record ?", "Save ! ", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
For J As Integer = 0 To DataGridStock.Rows.Count - 1 Step +1
Query1 = "Update Tempstock Set Type='" & LabelTrancode.Text & "', Prefix='" & Lblprefix.Text & "', Srl='" & TextINVNo.Text & "',
DOcDate='" & TextBoxdocdate.Text & "',Sno='" & DataGridStock.Rows(J).Cells(0).Value & "', Hsncode='" & DataGridStock.Rows(J).Cells(4).Value & "',
Branch='" & LBLBranchcode.Text & "',Taxcode='" & DataGridStock.Rows(J).Cells(5).Value & "',Code='" & DataGridStock.Rows(J).Cells(2).Value & "',
Qty='" + (DataGridStock.Rows(J).Cells(6).Value) + "',Rate='" + Int(DataGridStock.Rows(J).Cells(8).Value) + "',Unit='" & DataGridStock.Rows(J).Cells(7).Value & "'"
Dim query = String.Concat(Query1, ";")
con.Open()
cmd = New SqlCommand(query, con)
reader = cmd.ExecuteReader
reader.Close()
con.Close()
Next
MessageBox.Show(" Stock Updated")
End If
Catch ex As Exception
End Try
End Sub

System.Data.OleDb.OleDbException Additional information: Syntax error in INSERT INTO statement

I got this error and not able to solve this please someone reply.
An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement.
Dim cnnOLEDB As New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim cmdDelete As New OleDbCommand
Dim cmd As OleDbCommand
Dim cnn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\project\B-tech\FirstVBproject\LMSapp\LMSapp\Library2.accdb")
cnn.open()
Dim Bid, Bnmbr, bname, bauthor, Bdscptn, bcate, bpus, bprice, btype, byear, bpage, pcopy As String
'Dim catename, catdes As String
Dim insert As String
Bnmbr = BNBRTXT.Text
bname = TextBox1.Text
bauthor = TextBox2.Text
Bdscptn = TextBox3.Text
bpus = TextBox4.Text
bprice = TextBox5.Text
byear = TextBox6.Text
bpage = TextBox7.Text
pcopy = TextBox8.Text
'catdes = TextBox3.Text
insert = "INSERT INTO book (BookNumber,Name,Author,Descraption,Publication,Price,Year,Pages,Copy) VALUES ('" & Bnmbr & "','" & bname & "','" & bauthor & "','" & Bdscptn & "','" & bpus & "','" & bprice & "','" & byear & "','" & bpage & "','" & pcopy & "' )"
cmd = New OleDbCommand(insert, cnn)
cmdOLEDB = New OleDbCommand(insert, cnn)
cnn.GetType()
cmdOLEDB.ExecuteNonQuery()
MsgBox("data inserted", MsgBoxStyle.Information)
BNBRTXT.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
cnn.close()

VB.net and mysql data

i'm working an attendance system and its almost done but i have a problem in my time in and time out form. i already did the codes for time in and time out of students and its working quite well but my problem is after the day ends it must reset the data so it can gather a new data when another day starts.
this is my code for time in and out
Dim check As Boolean
Call connect()
Dim cmdd As New MySqlCommand("Select Count(*) from attendance_for_student WHERE Remarks = 'IN' ", dbconn)
Dim i As Integer = cmdd.ExecuteScalar()
cmdd = Nothing
dbconn.Close()
TextBox1 .Text = i
If student.Text = "" Then
MsgBox("Scan Your Code!", MsgBoxStyle.Critical)
Else
Call connect()
sql = "SELECT * FROM student WHERE Sbarcode='" & student.Text & "'"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader
Do While dbread.Read
Dim id As String = student.Text
Dim folder As String = "c:\jpnhs\"
Dim filename As String = System.IO.Path.Combine(folder, id & ".bmp")
PictureBox1.Image = Image.FromFile(filename)
FULLNAME.Text = dbread.Item(1).ToString & " " & dbread.Item(2).ToString & " " & dbread.Item(3).ToString
Loop
dbread.Close()
dbconn.Close()
End If
If Len(student.Text) = 8 Then
Call connect()
check = False
sql = "SELECT * FROM attendance_for_student WHERE Sbarcode = '" & student.Text & "' AND (remarks <>'IN' OR remarks <>'OUT')"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader
Do While dbread.Read
check = True
Loop
dbread.Close()
dbconn.Close()
If check = False Then
Call connect()
sql = "INSERT INTO attendance_for_student(Sbarcode,Time,Date,remarks) VALUES ('" & student.Text & "','" & LBLTime.Text & "','" & LBLDate.Text & "','IN')"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
dbconn.Close()
Search_Code()
Else
Call connect()
sql = "INSERT INTO attendance_for_student(Sbarcode,Time,Date,remarks) VALUES ('" & student.Text & "','" & LBLTime.Text & "','" & LBLDate.Text & "','OUT')"
dbcomm = New MySqlCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
dbconn.Close()
Search_Code()
End If
End If

Save all rows in Datagridview when Checkbox column is true

Good Morning
I have a program that looks like this.
Form Design
I have a button named Multiple Select and when I click that the button will call SaveCheckedRecords() and here is the code for it
Public Sub SaveCheckedRecords()
Dim failed = False
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(0).Value = True Then
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Label2.Text = DataGridView1.Item("ItemCode", i).Value
Label3.Text = DataGridView1.Item("Description", i).Value
Label4.Text = DataGridView1.Item("ReflectedQty", i).Value
Label5.Text = DataGridView1.Item("UOM", i).Value
Label6.Text = DataGridView1.Item("UnitPrice", i).Value
Label7.Text = DataGridView1.Item("Total", i).Value
Label8.Text = DataGridView1.Item("Remarks", i).Value
standard() '<------------- Call this Sub
insert() '<------------- Call this Sub
failed = True
Exit For
End If
Next
If Not failed Then
MsgBox("Please select an item to receive")
End If
End Sub
Now my goal based on the code above is to transfer the data from datagridview rows to labels and call some Subs
Here is the code for the standard and insert
Private Sub standard()
Dim con As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=inventory")
Dim cmd As MySqlCommand = New MySqlCommand("select StandardUOM,QtyPerUoM from item_master_list where ItemCode = '" & Label2.Text & "'", con)
Dim reader As MySqlDataReader
con.Open()
reader = cmd.ExecuteReader
While reader.Read
Label9.Text = reader.GetString("StandardUOM")
Label10.Text = reader.GetString("QtyPerUoM")
End While
End Sub
Private Sub insert()
DataGridView1.Columns.RemoveAt(0)
Dim con1 As MySqlConnection = New MySqlConnection("datasource=localhost;database=inventory;userid=root;password=admin1950")
Dim cmdinsert As MySqlCommand = New MySqlCommand("insert into receiving (RINo,PONo,ItemCode,Description,QtyPack,PackUoM,UnitPrice,Total,Remarks,ExpiryDate,QtyStan,StanUoM,PCS) values ('" & frm_Add_Receiving_Items.TextBox1.Text & "','" & Label1.Text & "','" & Label2.Text & "','" & Label3.Text & "','" & Label11.Text & "','" & Label5.Text & "','" & Label6.Text & "','" & Label7.Text & "','" & Label8.Text & "','" & DateTime.Now.ToString("yyyy-MM-dd") & "','" & Label12.Text & "','" & Label9.Text & "','" & Label10.Text & "')", con1)
con1.Open()
cmdinsert.ExecuteNonQuery()
con1.Close()
frm_Add_Receiving_Items.generate_rec_form()
updateRI()
loadlist1()
frm_Add_Receiving_Items.Button6.Enabled = False
Label2.Text = "Label2"
End Sub
All I want to do is to save the value of datagridview when checkboxcolumn(0) is True whats wrong with my code?
TYSM

Data gets stored in database from one tab page but it is not shown in another tab page in vb.net

I am using Visual Studio 2010 which has a form with a TabControl containing multiple tab pages.
1st tab page creates employee id and details about the employee which gets stored in the SQL server database successfully.2nd tab page has a ComboBox to display the employee id but it does not show the employee id which was created in the 1st tab page.When i close the project and run it again it displays the employee id.
How do i rectify this? Dim OpenDialog As New OpenFileDialog
With OpenDialog
.Filter = "Image Files (*.gif,*.jpg,*.jpeg,*.bmp,*.png)|*.gif;*.jpg;*.jpeg;*.bmp;*.png"
.Title = "Select A File"
End With
If gender.SelectedIndex = 0 Then
gend = "Male"
Else
gend = "Female"
End If
If eblood.SelectedIndex = 0 Then
blood = "A +ve"
ElseIf eblood.SelectedIndex = 1 Then
blood = "A -ve"
ElseIf eblood.SelectedIndex = 2 Then
blood = "B +ve"
ElseIf eblood.SelectedIndex = 3 Then
blood = "B -ve"
ElseIf eblood.SelectedIndex = 4 Then
blood = "AB +ve"
ElseIf eblood.SelectedIndex = 5 Then
blood = "AB -ve"
ElseIf eblood.SelectedIndex = 6 Then
blood = "O +ve"
Else
blood = "O -ve"
End If
If (String.IsNullOrWhiteSpace(eid.Text.Trim())) Or (String.IsNullOrWhiteSpace(fname.Text.Trim())) Or (String.IsNullOrWhiteSpace(lname.Text.Trim())) Or (String.IsNullOrWhiteSpace(gender.Text.Trim())) Or (String.IsNullOrWhiteSpace(gender.Text.Trim())) Or (String.IsNullOrWhiteSpace(country.Text.Trim())) Or (String.IsNullOrWhiteSpace(eaddress.Text.Trim())) Or (String.IsNullOrWhiteSpace(equali.Text.Trim())) Or (String.IsNullOrWhiteSpace(eblood.Text.Trim()) Or (String.IsNullOrWhiteSpace(TextBox_browse.Text.Trim()))) Then
MsgBox("Please Fill all the Fields", vbExclamation)
Else
Dim myconnection As SqlConnection
Dim mycommand As SqlCommand
myconnection = New SqlConnection("Data Source=localhost\sqlexpress;Initial Catalog=billing;Integrated Security=True")
Try
myconnection.Open()
mycommand = New SqlCommand("insert into b_emp_details([ed_id],[ed_first_name],[ed_last_name],[ed_dob],[ed_phone_number],[ed_gender],[ed_joining_date],[ed_country],[ed_address],[ed_qualification],[ed_blood_grp],[ed_image],[ed_created_by],[ed_created_date]) values ('" & eid.Text & "','" & fname.Text & "','" & lname.Text & "','" & dob.Text.ToString & "','" & ph.Text & "','" & gend & "','" & doj.Text.ToString & "','" & country.Text & "','" & eaddress.Text & "','" & equali.Text & "','" & blood & "','" & Trim(TextBox_browse.Text) & "','" & global_user & "','" & global_date & "')", myconnection)
mycommand.ExecuteNonQuery()
mycommand.CommandText = "UPDATE b_emp_details SET [ed_image] ='" & Trim(TextBox_browse.Text) & "' where [ed_id]='" & eid.Text & "'"
mycommand.Connection = myconnection
dr = mycommand.ExecuteReader
Dim newimage As New BitmapImage
newimage.BeginInit()
newimage.UriSource = (New Uri(OpenDialog.FileName, UriKind.RelativeOrAbsolute))
TextBox_browse.Text = OpenDialog.FileName
newimage.EndInit()
MessageBox.Show("Employee Successfully Created...")
eid.Text = ""
fname.Text = ""
lname.Text = ""
dob.Text = ""
ph.Text = ""
gender.Text = ""
doj.Text = ""
country.Text = ""
eaddress.Text = ""
equali.Text = ""
eblood.Text = ""
TextBox_browse.Text = ""
Call ResetBindings()
Catch ex As Exception
MsgBox("Error: " + ex.Message + "Invalid Data..Please Enter A Valid Data....")
'MsgBox("Invalid Data..Please Enter A Valid Data....")
myconnection.Close()
End Try
End If