?
Solved

How to reflect changes in dataset to database?

Posted on 2008-09-30
4
Medium Priority
?
635 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 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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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