hi guys i have develope a database based system recently
but its shows a error as in title do anyone can help me????
its realy urgent guys here is my code :

Imports System.Data

Public Class Form2

    Dim inc As Integer
    Dim maxrows As Integer


    Dim con As New OleDb.OleDbConnection

    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\database\mpp eelection1.mdb"
        con.Open()

        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String

        sql = "SELECT * FROM maklumatpel"
        da = New OleDb.OleDbDataAdapter(sql, con)

        da.Fill(ds, "record")

        con.Close()

        maxrows = ds.Tables("record").Rows.Count
        inc = -1

    End Sub

    Private Sub NavigateRecords()

        NamaTextBox.Text = ds.Tables("record").Rows(inc).Item("nama")
        No_icTextBox.Text = ds.Tables("record").Rows(inc).Item("no_ic")
        IDTextBox.Text = ds.Tables("record").Rows(inc).Item("id")
        IntakeTextBox.Text = ds.Tables("record").Rows(inc).Item("Intake")
        ProgramTextBox.Text = ds.Tables("record").Rows(inc).Item("program")

    End Sub
   


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form3.Show()
        Me.Hide()


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If inc <> maxrows - 1 Then
            inc = inc + 1
            NavigateRecords()
        Else
            MsgBox("No More Rows")
        End If
        
    End Sub


   
   

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If inc > 0 Then
            inc = inc - 1
            NavigateRecords()
        Else
            MsgBox("First Record")
        End If


    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Button5.Enabled = True
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button6.Enabled = False

        NamaTextBox.Clear()
        No_icTextBox.Clear()
        IDTextBox.Clear()
        IntakeTextBox.Clear()
        ProgramTextBox.Clear()
        inc = 0

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If inc <> -1 Then

            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow

            dsNewRow = ds.Tables("RECORD").NewRow()
            InitializeComponent()

            dsNewRow.Item("nama") = NamaTextBox.Text
            dsNewRow.Item("no_ic") = No_icTextBox.Text
            dsNewRow.Item("id") = IDTextBox.Text
            dsNewRow.Item("intake") = IntakeTextBox.Text
            dsNewRow.Item("program") = ProgramTextBox.Text


            ds.Tables("RECORD").Rows.Add(dsNewRow)

            da.Update(ds, "RECORD")

            MsgBox("New Record added to the Database")

            Button5.Enabled = False
            Button1.Enabled = True
            Button2.Enabled = True
            Button3.Enabled = True
            Button4.Enabled = True
            Button6.Enabled = True

        End If


    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("RECORD").Rows(inc).Delete()
        maxrows = maxrows - 1

        inc = 0
        NavigateRecords()
        da.Update(ds, "RECORD")


    End Sub
End Class

thanks in advance for those helping me....
regards - ren -

Recommended Answers

All 6 Replies

Remove lines # 19,20,21

still got problem, its run but dint add record to database and the error shown at update statement.

Can you post that error description, please?

its shows invalidcastexeption was unhandled when use nex button (button2)
and the system stucks at msgbox when use save button (button5) its dint save the record

Private Sub NavigateRecords()
if inc<ds.Tables("record").Rows.Count Then
NamaTextBox.Text = ds.Tables("record").Rows(inc).Item("nama").ToString()
No_icTextBox.Text = ds.Tables("record").Rows(inc).Item("no_ic").ToString()
IDTextBox.Text = ds.Tables("record").Rows(inc).Item("id").toString()
IntakeTextBox.Text = ds.Tables("record").Rows(inc).Item("Intake").ToString()
ProgramTextBox.Text = ds.Tables("record").Rows(inc).Item("program").ToString()
End If 
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  If inc < ds.Tables("record").Rows.Count Then
      inc = inc + 1
      NavigateRecords()
   Else
      MsgBox("No More Rows")
   End If
End Sub

problem was solved....thanks for the help...
regards -ren-

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.