Hi guys,
Firstly sorry if I've posted in the wrong section etc.
I'm Very new to VB and this is my first project for my college course.
My plan is to make a very simple payroll system that's linked to a database, the only two calculations i have on the form are the 'Hourly pay' and 'Contract hours' they add together in the 'Gross pay' textbox...I know i haven't added tax etc but like i said this is very very basic.
My plan was to make a simple payroll system that the user could update and this would also update in the database.
I was going well with the coding but i have come across a Syntax error when i try to update the data.
This is whats popping up.
Attachment 98475
I will add the code as well.
Like i said i'm very new to this to be nice haha...the whole thing could be wrong for all i know lol
Public Class JSDPAYROLL
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim cb As New OleDb.OleDbCommandBuilder(da)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = E:/AddressBook.mdb"
con.ConnectionString = dbProvider & dbSource
sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AddressBook")
MaxRows = ds.Tables("AddressBook").Rows.Count
inc = -1
End Sub
Private Sub NavigateRecords()
txtFirstName.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
txtSurname.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
txtContractHours.Text = ds.Tables("AddressBook").Rows(inc).Item(10)
txtHourlyPay.Text = ds.Tables("AddressBook").Rows(inc).Item(9)
End Sub
Private Sub btnback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnback.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("First Record")
End If
End Sub
Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
ds.Tables("AddressBook").Rows(inc).Item(2) = txtSurname.Text
da.Update(ds, "AddressBook")
MsgBox("Data updated")
End Sub
Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
btnCommit.Enabled = True
btnAddNew.Enabled = False
btnDelete.Enabled = False
txtFirstName.Clear()
txtSurname.Clear()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
inc = 0
NavigateRecords()
txtFirstName.Clear()
txtSurname.Clear()
txtContractHours.Clear()
txtHourlyPay.Clear()
txtGrossPay.Clear()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation Cancelled")
Exit Sub
End If
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
NavigateRecords()
End Sub
Private Sub TblContactsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.TblContactsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.AddressBookDataSet)
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngrosspay.Click
txtGrossPay.Text = Val(txtContractHours.Text) * Val(txtHourlyPay.Text)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
On Error GoTo errorfound
PrintForm1.Print()
Exit Sub
errorfound:
MsgBox("Error found in Printing")
Resume Next
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveFileDialog1.ShowDialog()
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim FileToSave As String = SaveFileDialog1.FileName
Dim objwriter As New System.IO.StreamWriter(FileToSave)
objwriter.Write(txtFirstName)
objwriter.Close()
End Sub
Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
End Sub
Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("AddressBook").NewRow()
dsNewRow.Item(1)("FirstName") = txtFirstName.Text
dsNewRow.Item(2)("Surname") = txtSurname.Text
ds.Tables("AddressBook").Rows.Add(dsNewRow)
da.Update(ds, "AddressBook")
MsgBox("New Record added to the Database")
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True >
btnDelete.Enabled = True
End If
End Sub
End Class
Any help be great thanks :)
Firstly sorry if I've posted in the wrong section etc.
I'm Very new to VB and this is my first project for my college course.
My plan is to make a very simple payroll system that's linked to a database, the only two calculations i have on the form are the 'Hourly pay' and 'Contract hours' they add together in the 'Gross pay' textbox...I know i haven't added tax etc but like i said this is very very basic.
My plan was to make a simple payroll system that the user could update and this would also update in the database.
I was going well with the coding but i have come across a Syntax error when i try to update the data.
This is whats popping up.
Attachment 98475
I will add the code as well.
Like i said i'm very new to this to be nice haha...the whole thing could be wrong for all i know lol
Public Class JSDPAYROLL
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim cb As New OleDb.OleDbCommandBuilder(da)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = E:/AddressBook.mdb"
con.ConnectionString = dbProvider & dbSource
sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AddressBook")
MaxRows = ds.Tables("AddressBook").Rows.Count
inc = -1
End Sub
Private Sub NavigateRecords()
txtFirstName.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
txtSurname.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
txtContractHours.Text = ds.Tables("AddressBook").Rows(inc).Item(10)
txtHourlyPay.Text = ds.Tables("AddressBook").Rows(inc).Item(9)
End Sub
Private Sub btnback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnback.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("First Record")
End If
End Sub
Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
ds.Tables("AddressBook").Rows(inc).Item(2) = txtSurname.Text
da.Update(ds, "AddressBook")
MsgBox("Data updated")
End Sub
Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
btnCommit.Enabled = True
btnAddNew.Enabled = False
btnDelete.Enabled = False
txtFirstName.Clear()
txtSurname.Clear()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
inc = 0
NavigateRecords()
txtFirstName.Clear()
txtSurname.Clear()
txtContractHours.Clear()
txtHourlyPay.Clear()
txtGrossPay.Clear()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation Cancelled")
Exit Sub
End If
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
NavigateRecords()
End Sub
Private Sub TblContactsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.TblContactsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.AddressBookDataSet)
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngrosspay.Click
txtGrossPay.Text = Val(txtContractHours.Text) * Val(txtHourlyPay.Text)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
On Error GoTo errorfound
PrintForm1.Print()
Exit Sub
errorfound:
MsgBox("Error found in Printing")
Resume Next
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveFileDialog1.ShowDialog()
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim FileToSave As String = SaveFileDialog1.FileName
Dim objwriter As New System.IO.StreamWriter(FileToSave)
objwriter.Write(txtFirstName)
objwriter.Close()
End Sub
Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
End Sub
Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("AddressBook").NewRow()
dsNewRow.Item(1)("FirstName") = txtFirstName.Text
dsNewRow.Item(2)("Surname") = txtSurname.Text
ds.Tables("AddressBook").Rows.Add(dsNewRow)
da.Update(ds, "AddressBook")
MsgBox("New Record added to the Database")
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True >
btnDelete.Enabled = True
End If
End Sub
End Class
Any help be great thanks :)