Solved

Adding a new record to the dataset.

Posted on 2004-10-08
4
218 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Nerdy_Girl88
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 500 total points
ID: 12257258
U can have the databinding statements for the textboxes and comboboxes in a particular function

Public Sub DataBindingsControl
textBox1.DataBindings.Add(new Binding("Text", ds.Tables[0], "First"));

End Sub


When u want to add a new record to the dataset remove the databindings from the controls

databindings.clear

After u add a new record to the dataset again call the function DataBindingsControl, to set the databindings for all the controls



0
 

Author Comment

by:Nerdy_Girl88
ID: 12257272
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.
0
 

Expert Comment

by:DigitalDan3
ID: 14710294
Please Post the Tutorial

Thanks

Dan
0
 

Author Comment

by:Nerdy_Girl88
ID: 14758638
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question