I have been trying to write a program for a company that I work for, that would do assist tracking as well as give an overview of where the assists are.
The idea is to have a database with unique numbers on them that is allocated to all the hardware.
When a "desk" button is pressed it will show the info form that desk and it can be edited from there.
I roughly have what I was looking for, but I'm struggling with an issue when I update data, the data is somehow placed in the incorrect row...
E.g:
Desk Name : TL1 PC : 0001 monitor : 0002
Desk Name : TL2 PC : 0003 monitor : 0004
If I update the fist data entry alone it works fine.. however when I update the second entry it gets saved onto the first entry
E.g:
Desk Name : TL2 PC : 0003 monitor : 0004
Desk Name : TL2 PC : 0003 monitor : 0004
This is the code I have so far, any help would be very appreciated.
Public Class Form1
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 MaxRows As Integer
Dim inc As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Lib_9th_NLDataSet.tblContacts' table. You can move, or remove it, as needed.
    Me.TblContactsTableAdapter.Fill(Me.Lib_9th_NLDataSet.tblContacts)
    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source = \\elite03\IT\Assets\Lib 9th NL.mdb"
    con.ConnectionString = dbProvider & dbSource
    con.Open()
    sql = "SELECT Desk,Pc,Monitor,Keyboard,Phone,Laptop FROM tblcontacts"
    da = New OleDb.OleDbDataAdapter(sql, con)
    da.Fill(ds, "Lib_9th_NL")
    con.Close()
    MaxRows = Lib_9th_NLDataSet.tblContacts.Rows(inc).Item(inc)
    inc = 0
End Sub
Private Sub NavigateRecords()
    txtDesk_Name.Text = ds.Tables("Lib_9th_NL").Rows(inc).Item(0)
    txtPC.Text = ds.Tables("Lib_9th_NL").Rows(inc).Item(1)
    txtMonintor.Text = ds.Tables("Lib_9th_NL").Rows(inc).Item(2)
    txtKeyboard.Text = ds.Tables("Lib_9th_NL").Rows(inc).Item(3)
    txtPhone.Text = ds.Tables("Lib_9th_NL").Rows(inc).Item(4)
    txtlaptop.Text = ds.Tables("Lib_9th_NL").Rows(inc).Item(5)
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
    Me.Validate()
    Me.TblContactsBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.Lib_9th_NLDataSet)
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
    If inc <> MaxRows - 0 Then
        inc = inc + 1
        NavigateRecords()
    Else
        MsgBox("No More Rows")
    End If
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
    If inc > 0 Then
        inc = inc - 1
        NavigateRecords()
    Else
        MsgBox("First Record")
    End If
End Sub
Private Sub btnAddNew_Click(sender As Object, e As EventArgs) Handles btnAddNew.Click
    btnCommit.Enabled = True
    btnUpdate.Enabled = False
    btnDelete.Enabled = False
    btnAddNew.Enabled = False
    txtDesk_Name.Clear()
    txtPC.Clear()
    txtMonintor.Clear()
    txtKeyboard.Clear()
    txtPhone.Clear()
    txtlaptop.Clear()
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
    btnCommit.Enabled = False
    btnAddNew.Enabled = True
    btnUpdate.Enabled = True
    btnDelete.Enabled = True
    inc = 0
    NavigateRecords()
End Sub
Private Sub btnCommit_Click(sender As Object, e As EventArgs) Handles btnCommit.Click
    If inc <> -1 Then
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow
        dsNewRow = ds.Tables("Lib_9th_NL").NewRow()
        dsNewRow.Item("desk") = txtDesk_Name.Text
        dsNewRow.Item("PC") = txtPC.Text
        dsNewRow.Item("Monitor") = txtMonintor.Text
        dsNewRow.Item("Keyboard") = txtKeyboard.Text
        dsNewRow.Item("Phone") = txtPhone.Text
        dsNewRow.Item("Laptop") = txtlaptop.Text
        ds.Tables("Lib_9th_NL").Rows.Add(dsNewRow)
        da.Update(ds, "Lib_9th_NL")
        MsgBox("New Record added to the Database")
        btnCommit.Enabled = False
        btnAddNew.Enabled = True
        btnUpdate.Enabled = True >
        btnDelete.Enabled = True
    End If
End Sub
Private Sub btnDelete_Click(sender As Object, e As 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("Lib_9th_NL").Rows(inc).Delete()
    MaxRows = MaxRows - 1
    inc = 0
    da.Update(ds, "Lib_9th_NL")
    NavigateRecords()
End Sub
Private Sub TL1_Click(sender As Object, e As EventArgs) Handles TL1.Click
    txtDesk_Name.Text = Lib_9th_NLDataSet.tblContacts.Rows(0).Item(1)
    txtPC.Text = Lib_9th_NLDataSet.tblContacts.Rows(0).Item(2)
    txtMonintor.Text = Lib_9th_NLDataSet.tblContacts.Rows(0).Item(3)
    txtKeyboard.Text = Lib_9th_NLDataSet.tblContacts.Rows(0).Item(4)
    txtPhone.Text = Lib_9th_NLDataSet.tblContacts.Rows(0).Item(5)
    txtlaptop.Text = Lib_9th_NLDataSet.tblContacts.Rows(0).Item(6)
End Sub
Private Sub Ret1_Click(sender As Object, e As EventArgs) Handles Ret1.Click
    txtDesk_Name.Text = Lib_9th_NLDataSet.tblContacts.Rows(1).Item(1)
    txtPC.Text = Lib_9th_NLDataSet.tblContacts.Rows(1).Item(2)
    txtMonintor.Text = Lib_9th_NLDataSet.tblContacts.Rows(1).Item(3)
    txtKeyboard.Text = Lib_9th_NLDataSet.tblContacts.Rows(1).Item(4)
    txtPhone.Text = Lib_9th_NLDataSet.tblContacts.Rows(1).Item(5)
    txtlaptop.Text = Lib_9th_NLDataSet.tblContacts.Rows(1).Item(6)
End Sub
End Class
 
     
     
    