Link to home
Start Free TrialLog in
Avatar of Nerdy_Girl88
Nerdy_Girl88

asked on

Adding a new record to the dataset.

Hi, this probably sound like a silly Question....So should be some easy point.

I want to Add a new record to a dataSet,  I know how to add a new record to the dataset.  My problem is setting the form controls up to accept the new data.

Currently I have a form with a combobox and two text boxes.

They are all bound to the same dataset. Dataset1.

I have a add button that will clear the text boxes and allow the user to enter data form the new record.  This is where the problem starts,  I only clear the textboxes for the user, the binding architeture recognises it as a changed dataset record. I have a button that will save the values in the text boxes as a new row in the dataset.  This work good.  accpet the current record in the dataset is effected.  

My problem occurred when i tried to cancel the add action, the cleared forms stay and the dataset through they were changes to the current record.

How do i prevent the dataset from accepting the change made.

How do I prepare the form to accpet new values with out effecting the bound dataset.
thanks
ASKER CERTIFIED SOLUTION
Avatar of 123654789987
123654789987

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nerdy_Girl88
Nerdy_Girl88

ASKER

Is this nessary, removing the binding. To add a new record, is it a common practice.  

I have am using this function on cancel so it will replace all the data cleared by the add button action.
------------------------------------------------
Private Sub rejectChanges()
        'set all the value back to what they were before
        Dim intRecordPosition As Integer = Me.BindingContext(Me.mDataObj.DsFrmModel1, "Model").Position
        Dim curRow As DataRow = Me.mDataObj.DsFrmModel1.Model.Rows(intRecordPosition)

        Try
            Me.txtModelID.Text = curRow("Model_ID", DataRowVersion.Original).ToString
            Me.txtModelName.Text = curRow("Model_Name", DataRowVersion.Original).ToString
            Me.txtPicture.Text = curRow("Picture", DataRowVersion.Original).ToString
            Me.RtxFeatures.Text = curRow("Standard Features", DataRowVersion.Original).ToString

        Catch ex As Exception
            MessageBox.Show(ex.Message, "error in rejectChanges")
        End Try
    End Sub

------------------------------------------------

Thanks.  I have found a good tutorial that is showing me how to add the add,edit and delete buttons

thanks, here are some easy points.
Please Post the Tutorial

Thanks

Dan
Sorry the tutorial was found in a book that i brought called.

Advanced Programming in VB.net
by Julia Case Bradley and Anita C. Millspaugh.

I also have:

Programming in VB.net
by Julia Case Bradley and Anita C. Millspaugh.

These books where excellent for learning the basics.
Along with this help website.

Sorry. can't help much this one.