Dataset Manipulation in C#

Working with dataset manipulations 

1)fill method is used to get the data from database server into dataset 

2)update method is used to store the modifications of dataset into database 

3)command builder is a pre-defined class, which is used to create the syntaxes of DML statements with the help of dataadapter 

4)command builder is used only to create the syntax but not to execute 

5)methods of commandbuilder class 

        a)Getinsert command()…..returns the syntax of insert statement 

        b)Getdelete command()….returns the syntax of delete statement 

        c)Getupdate command()methods b,c works only when table contains a primary key

 

observation on DataBind() with asp.net ? 

DataBind () converts webserver controls into Html controls

 

Example on dataset manipulations with oracle  

Open oracle software 

Create a table as follows 

Create table products(pno number primarykey, pname varchar2(10), cost number

 

Open windows forms app project 

Start->programs->Microsoft visual studio 2010->Microsoft Visual studio 2010->file menu->new-> 

project->select visual c# from installed templates->select windows forms application project   

place 2 buttons with text get & save changes 

place a datagridview control 

using System.Data.OleDb;

 

using System; 

using System.Collections.Generic; 

using System.ComponentModel; 

using System.Data; 

using System.Drawing; 

using System.Linq; 

using System.Text; 

using System.Windows.Forms; 

using System.Data.OleDb;

 

namespace WindowsFormsApplication22 

{ 

    public partial class Form1 : Form 

    { 

        public Form1() 

        { 

            InitializeComponent(); 

        }

 

        static OleDbConnection cn = new OleDbConnection("userid=scott;password=tiger;provider=msdaora.1"); 

        OleDbDataAdapter da = new OleDbDataAdapter("select * from products", cn); 

        DataSet ds=new DataSet();

 

        private void Form1_Load(object sender, EventArgs e) 

        { 

        }

 

        private void button1_Click(object sender, EventArgs e) 

        { 

            da.Fill(ds, "d"); // d is table alias name 

            dataGridView1.DataSource = ds.Tables["d"]; 

        }

 

        private void button2_Click(object sender, EventArgs e) 

        { 

            OleDbCommandBuilder cb = new OleDbCommandBuilder(da); 

 

            MessageBox.Show(cb.GetInsertCommand().CommandText); 

            MessageBox.Show(cb.GetDeleteCommand().CommandText); 

            MessageBox.Show(cb.GetUpdateCommand().CommandText);

 

            da.Update(ds, "d");

 

            MessageBox.Show("the changes are stored"); 

        } 

    } 

}

 

Execute the project press F5