Visual Basic 2005 Error

I m getting a error message while Updating. Can anyone help me please?

Page 1 of 1

2 Replies - 1119 Views - Last Post: 06 July 2010 - 07:04 AM Rate Topic: -----

#1 bhaskor88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-July 10

Visual Basic 2005 Error

Posted 06 July 2010 - 05:58 AM

Hi everyone, my name is Bhaskor Jyoti Sarmah. I am doing B.SC(IT) under a local University.I have to submit a minor project before 9 july 2010. I have developed a small project hoping that if everything is correct then I will modify it for my minor project. I am using Visual Studio 2005. I am getting a error message while trying to update the database. I am providing the code below and a picture of the error message in attachment. I will be very thank full if someone helps me to overcome this problem. I will be waiting for some help thank you.

The codes are:

Imports system.data
Public Class Form1
    Dim inc As Integer
    Dim max As Integer
    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AddressBookDataSet.tblContacts' table. You can move, or remove it, as needed.
        'Me.TblContactsTableAdapter.Fill(Me.AddressBookDataSet.tblContacts)
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AddressBook.mdb"
        con.Open()
        sql = "SELECT * from tblcontacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "AddressBook")
        con.Close()
        max = 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)
    End Sub

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

    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If inc > 0 Then
            inc = inc - 1
            NavigateRecords()
        ElseIf inc = -1 Then
            MsgBox("No Records Yet")
        ElseIf inc = 0 Then

            MsgBox("First Record")
        End If

    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        If inc <> max - 1 Then
            inc = max - 1
            NavigateRecords()
        End If

    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 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
        btnupdate.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()

    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(da)
            Dim dsNewRow As DataRow
            dsNewRow = ds.Tables("AddressBook").NewRow()
            dsNewRow.Item("FirstName") = txtFirstName.Text
            dsNewRow.Item("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

    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) = Windows.Forms.DialogResult.No Then

            MsgBox("Operation Cancelled")
            Exit Sub
        End If
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        ds.Tables("AddressBook").Rows(inc).Delete()
        max = max - 1
        inc = 0
        NavigateRecords()
        da.Update(ds, "AddressBook")

    End Sub
End Class


Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Visual Basic 2005 Error

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual Basic 2005 Error

Posted 06 July 2010 - 06:47 AM

Well first it would be extremely helpful if we knew what error(s) you're receiving.
Was This Post Helpful? 0
  • +
  • -

#3 Bacanze  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 202
  • Joined: 09-April 10

Re: Visual Basic 2005 Error

Posted 06 July 2010 - 07:04 AM

View Postbhaskor88, on 06 July 2010 - 04:58 AM, said:

I am providing the code below and a picture of the error message in attachment.


As PsychoCoder said, you haven't posted what error message your getting, did you forget?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1