[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to reflect changes in dataset to database?

Posted on 2008-09-30
4
Medium Priority
?
641 Views
Last Modified: 2013-12-17
#i have made changes in dataset like added some records using

private void btnadd_Click(object sender, EventArgs e)
        {
            try
            {
                DataRow r = dsNorthwind.Tables[0].NewRow();
                if (txtid.Text != "")
               {
                   r[0] = txtid.Text;

                   if (txtcname.Text != "")
                   {
                        r[1] = txtcname.Text;
                        r[2] = txtcontact.Text;
                        r[3] = txttitle.Text;
                        r[4] = txtaddr.Text;
                        r[5] = txtcity.Text;
                        r[6] = txtregion.Text;
                        r[7] = txtcode.Text;
                        r[8] = txtcountry.Text;
                        r[9] = txtphone.Text;
                        r[10] = txtfax.Text;
                        dsNorthwind.Tables[0].Rows.Add(r);
                        dataGridView1.DataSource = dsNorthwind.Tables[0];

                       MessageBox.Show("1 row inserted", "Insert", MessageBoxButtons.OK,  
                       MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
                       MessageBoxOptions.DefaultDesktopOnly);
                       
                    }
                    else
                    {
                        MessageBox.Show("Company Name is required", "Mandatory",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Information,
                      MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                     
                      txtcname.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Customer ID is mandatory ", "Mandatory", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                   
               txtid.Focus();
                }
                           }
            catch (Exception ex) { MessageBox.Show("duplicate values not allowed"); }
           
        }

#deleted data using following
        private void btndelete_Click(object sender, EventArgs e)
        {
            foreach (DataRow r in dsNorthwind.Tables[0].Rows)
            {
                if (r[0].Equals(txtid.Text))
                {
                   dsNorthwind.Tables[0].Rows.Remove(r);
                   
                    break;

                }
            }
            dsNorthwind.AcceptChanges();
         
            txtid.Text = "";
            txtcname.Text = "";
            txtcontact.Text = "";
            txttitle.Text = "";
            txtaddr.Text = "";
            txtcity.Text = "";
            txtregion.Text = "";
            txtcode.Text = "";
            txtcountry.Text = "";
            txtphone.Text = "";
            txtfax.Text = "";
         
        }

# and on click of "save" buttton i want to store these in table northwind.dbo.customers
can u suggest me any way ASAP?
0
Comment
Question by:reval1
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 22604362
You probably have a DataAdapter to fill your dataset, you can reuse this same DataAdapter to push back updates to the DB. See http://www.java2s.com/Code/CSharp/Database-ADO.net/UpdatetableusingSqlDataAdapter.htm
0
 
LVL 41

Assisted Solution

by:graye
graye earned 1000 total points
ID: 22605534
Take a look at this article on ADO.Net.... it's from a VB.Net perspective, but the concepts are the same.
http://home.hot.rr.com/graye/Articles/SavingDataADO.htm 
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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