Wednesday, 28 August 2013

Explain the process of adding, updating and deleting records with an example.

Updating Records:
To reference a particular column (item) in a row of the DataSet, the code is this:
Ds.Tables(“AddressBook”). Rows(2).item(1)
That will return whatever is at item 1 on Row 2.
As well as returning a value, you can also set a value. You do it like this:
            Ds.Tables(“AddressBook”). Rows(2).item(1) = “jane”
Now item 1 Row 2 will contain the text “Jane”. This wontm giweverm effect tge database! The changes will just get made to the DataSet. To illustrate this, add the following code to your btnUdate:
            Ds.Tables(“AddressBook”).Rows(inc).Item(1) =
            txtFirstName.Test
            ds.Tables(“AddressBook”).Rows(in).Item(2) =
            txtSurname.Text
            MsgBox(“Data updated”)
Run your program, and click the Next Record button to move to first record. “John” should be displayed in your first textbox, and “Smith” in the second textbox. Adding Records:
Adding a new record is slightly more complex. First, you have to add a new Row to the DataSet, then commit the new Row to the Database.
But the Add New Record button on our form isquite simple. The only thing it does is to switch off other buttons, and clear the textboxes, ready for new entry. Here,s the code for your Add New Record button:
            btnCommit.Enabled = True
            btnAddNew.Enabled =False
            btnUpdate.Enabled = False
            btnDelete.Enabled = False
            txtFirstName.Clear()
            txtSurname.Clear()

Deleting Record:
The code to delete a record is a little easier than last time. Double click your btnDelete and the following:
            Dim cb As New OleDb. OleDbCommandBuilder()
            Ds. Tables(“AddressBook”).Rows(inc).Delete()
            MaxRows = MaxRows -1
            Inc = 0
            NavigateRecords()
            Da.Update(ds, “ AddressBook”)

No comments:

Post a Comment