Small is New Big in C#


Update DataSet using SqlDataAdapter

leave a comment »

        private DataSet ds;
        private SqlConnection sqlconn;
        private SqlCommand comm;
        private SqlDataAdapter sqlda;
        private SqlCommandBuilder commBuilder;

        public SqlConnection getcon()
            string M_str_sqlcon = "Data Source=(local);Database=Northwind;user Id=sa;PWD=";
            SqlConnection mycon = new SqlConnection(M_str_sqlcon);
            return mycon;

        private void btnExportSql_Click(object sender, EventArgs e)
            for (int i = 0; i < ds.Tables["Categories"].Rows.Count; i++)
                ds.Tables["Categories"].Rows[i][1] = "Teeeeest";
            sqlda.Update(ds, "Categories");
            dataGridView1.DataSource = ds.Tables["Categories"];

        private void frmMain_Load(object sender, EventArgs e)
            sqlconn = this.getcon();
            comm = sqlconn.CreateCommand();
            comm.CommandText = "SELECT CategoryID,CategoryName, Description FROM Categories";
            sqlda = new SqlDataAdapter(comm);
            commBuilder = new SqlCommandBuilder(sqlda);
            ds = new DataSet();
            sqlda.Fill(ds, "Categories");
            dataGridView1.DataSource = ds.Tables["Categories"];


Written by nauhil

August 27, 2010 at 1:16 pm

Posted in Tips of C#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: