Solved

Adding a new record to the dataset.

Posted on 2004-10-08
4
216 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now