Solved

How to reflect changes in dataset to database?

Posted on 2008-09-30
4
620 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 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 66
How to add <appSettings> to the webconfig file 2 27
C# bracket error 3 32
VB.Net WebRequest Code from JSON curl 9 16
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 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