Solved

How to reflect changes in dataset to database?

Posted on 2008-09-30
4
612 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
4 Comments
 
LVL 69

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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.

760 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

21 Experts available now in Live!

Get 1:1 Help Now