Solved

Adding a new record to the dataset.

Posted on 2004-10-08
4
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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