Solved

How to reflect changes in dataset to database?

Posted on 2008-09-30
4
627 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
[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
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 250 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 250 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

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