i really don't know how to slove the erro in my program..

..can you please help me?? thank you in advance
,..

Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim cmd As New OleDb.OleDbCommand
    Dim da As New OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim sql As String
    Dim pos As Integer = 0
    Dim recordcount As Integer = 0


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER = microsoft.ace.oledb.12.0;data source=dbcontacts.accdb"
        con.Open()

        sql = "SELECT * from tblcontacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "CONTACTS_DS")
        con.Close()

        recordcount = ds.Tables("CONTACTS_DS").Rows.Count
        bindcontrols()


    End Sub
    Private Sub bindcontrols()

        ds = New DataSet("CONTACTS_DS")
        da.Fill(ds, "CONTACTS_DS")

        txtid.Text = ds.Tables("CONTACTS_DS").Rows(pos).Item("contactid")
        txtname.Text = ds.Tables("CONTACTS_DS").Rows(pos).Item("Name")
        txtmobileno.Text = ds.Tables("CONTACTS_DS").Rows(pos).Item("Mobileno")

    End Sub


    Private Sub cleartext()
        txtid.Clear()
        txtname.Clear()
        txtmobileno.Clear()
    End Sub

    Private Sub cmdnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnext.Click
        If pos < recordcount - 1 Then

            pos = pos + 1
            bindcontrols()
        End If
    End Sub

    Private Sub cmdprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdprevious.Click
        If pos > 0 Then

            pos = pos - 1
            bindcontrols()
        End If
    End Sub

    Private Sub cmdlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlast.Click
        pos = recordcount - 1
        bindcontrols()
    End Sub

    Private Sub cmdfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdfirst.Click
        pos = 0
        bindcontrols()
    End Sub

    Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
        cleartext()
        txtid.Focus()

    End Sub

    Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
        con.Open()
        sql = "INSERT INTO tblcontacts VALUES(' " & txtid.Text & "','" & txtname.Text & "','" & txtmobileno.Text & "')"
        cmd = New OleDb.OleDbCommand(sql, con)
        cmd.ExecuteNonQuery()
        con.Close()

        ds = New DataSet("CONTACT_DS")
        da.Fill(ds, "CONTACT_DS")
        recordcount = recordcount + 1
        bindcontrols()

    End Sub

    Private Sub cmdedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdedit.Click
        txtid.Focus()

    End Sub

    Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
        con.Open()

        sql = "UPDATE tblcontacts SET Name='" & txtname.Text & "', MobileNo='" & txtmobileno.Text & "'WHERE contactID='" & txtid.Text & "'"
        cmd = New OleDb.OleDbCommand(sql, con)
        cmd.ExecuteNonQuery()
        con.Close()

        ds = New DataSet("CONTACT_DS")
        da.Fill(ds, "CONTATCS_DS")
        bindcontrols()

    End Sub

    Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click
        con.Open()
        da.DeleteCommand = con.CreateCommand

        sql = "DELETE FROM tblcontacts WHERE contactid = '" & txtid.Text & "'"
        cmd = New OleDb.OleDbCommand(sql, con)
        cmd.ExecuteNonQuery()
        con.Close()


        ds = New DataSet("CONTACT_DS")
        recordcount = recordcount - 1
        pos = pos - 1
        bindcontrols()

    End Sub

    Private Sub cmdsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsearch.Click
        sql = "SELECT * FROM tblcontacts WHERE contactid='" & txtsearch.Text & "'"
        da = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("CONTACT_DS")
        da.Fill(ds, "CONTACT_DS")
        pos = 0
        bindcontrols()

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        sql = "SELECT * FROM tblcontacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("CONTACT_DS")
        da.Fill(ds, "CONTACT_DS")
        pos = 0
        bindcontrols()

    End Sub

    Private Sub txtname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtname.TextChanged

    End Sub
End Class

Remove the lines #27 and 28

Remove the lines #27 and 28

but the problem was the line #30

and it state that "make sure that the maximum index on the list is less than the list size"
;;;

but the problem was the line #30

And what comes before line 30? excatly, line 27 and 28!.
You creating a new dataset. every time. You should work with the one you already filled in your form_load event.

And what comes before line 30? excatly, line 27 and 28!.
You creating a new dataset. every time. You should work with the one you already filled in your form_load event.

a tried to remove the line 27 and 28 but nothings happen

im sorry if im asking to much

this is our final project so i really need your help

when does the error happen. if it happens when you seach then you may have to check if the search is returning any thing before calling binding controls sub

when does the error happen. if it happens when you seach then you may have to check if the search is returning any thing before calling binding controls sub

it did not want to run due to error

I've tried changing the code

but I just don't know if there is any difference at first, but now it can run..

Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim cmd As New OleDb.OleDbCommand
    Dim da As New OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim sql As String
    Dim pos As Integer = 0
    Dim recordcount As Integer = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER = Microsoft.Ace.OLEDB.12.0;Data Source=tblcontacts.accdb"
        con.Open()
        sql = "SELECT* from contacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "CONTACTS_DS")
        con.Close()

        recordcount = ds.Tables("CONTACTS_DS").Rows.Count
        bindcontrols()

    End Sub

    Private Sub bindcontrols()


        txtid.Text = ds.Tables("CONTACTS_DS").Rows(pos).Item("ID")
        txtname.Text = ds.Tables("CONTACTS_DS").Rows(pos).Item("Name")
        txtmobileno.Text = ds.Tables("CONTACTS_DS").Rows(pos).Item("mobileno")

    End Sub

    Private Sub cleartext()
        txtid.Clear()
        txtname.Clear()
        txtmobileno.Clear()

    End Sub

    Private Sub cmdnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnext.Click
        pos = pos + 1
        bindcontrols()
    End Sub

    Private Sub cmdprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdprevious.Click
        pos = pos - 1
        bindcontrols()
    End Sub

    Private Sub cmdfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdfirst.Click
        pos = 0
        bindcontrols()
    End Sub

    Private Sub cmdlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlast.Click
        pos = recordcount - 1
        bindcontrols()
    End Sub

    Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
        cleartext()
        txtid.Focus()
    End Sub

    Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
        con.Open()
        sql = "INSERT INTO tblcontacts VALUES ('" & txtid.Text & "','" & txtname.Text & "','" & txtmobileno.Text & "')"
        cmd = New OleDb.OleDbCommand(sql, con)
        cmd.ExecuteNonQuery()
        con.Close()

        ds = New DataSet("CONTACTS_DS")
        da.Fill(ds, "CONTACTS_DS")
        recordcount = recordcount + 1
        bindcontrols()
    End Sub

    Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click
        con.Open()
        sql = "DELETE FROM tblcontacts WHERE ID='" & txtid.Text & "'"
        cmd = New OleDb.OleDbCommand(sql, con)
        cmd.ExecuteNonQuery()
        con.Close()

        ds = New DataSet("CONTACTS_DS")
        da.Fill(ds, "CONTACTS_DS")
        recordcount = recordcount - 1
        pos = pos - 1
        bindcontrols()
    End Sub

    Private Sub cmdedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdedit.Click
        txtid.Focus()

    End Sub

    Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
        con.Open()
        sql = "UPDATE tblcontacts SET Name='" & txtname.Text & "',mobileno='" & txtmobileno.Text & "'WHERE ID='" & txtid.Text & "')"
        cmd = New OleDb.OleDbCommand(sql, con)
        cmd.ExecuteNonQuery()
        con.Close()

        ds = New DataSet("CONTACTS_DS")
        da.Fill(ds, "CONTACTS_DS")
        bindcontrols()
    End Sub

    Private Sub cmdrefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdrefresh.Click
        sql = "SELECT * FROM tblcontacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("CONTACTS_DS")
        pos = 0
        bindcontrols()
    End Sub

    Private Sub cmdsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsearch.Click
        sql = "SELECT * FROM tblcontacts WHERE ID ='" & txtsearch.Text & "'"
        da = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("CONTACTS_DS")
        da.Fill(ds, "CONTACTS_DS")
        pos = 0
        bindcontrols()

    End Sub
End Class

so is your problem fixed?
you may want to check if ds has any rows at the beginning on binding controles.

so is your problem fixed?
you may want to check if ds has any rows at the beginning on binding controles.

yes thank you for those who help me!!

godbless

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.