?
Solved

Adding a new record to the dataset.

Posted on 2004-10-08
4
Medium Priority
?
224 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 1500 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 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