Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends...
I have a written a function in a separate class file which return Dataset. This function help me to bind the datagridview.
C#
public DataSet dsreturn_edit(DataSet ds, String qry)
        {
            try
            {

                if (conn.State == ConnectionState.Closed)
                { conn.Open(); }

                OleDbCommand itemcmd = new OleDbCommand(qry, conn);
                OleDbDataAdapter adapter = new OleDbDataAdapter(itemcmd);
                adapter.Fill(ds, "DailyData");
                return ds;
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error loading data to dataset. DETAIL: " + ex.ToString(), "My Application");
            }
            finally
            {
                conn.Close();
            }
            return ds;
        }

In the form load event I am binding the Datagridview like this
C#
BindingSource bs = new BindingSource();
           DataSet ds = new DataSet();
           bs.DataSource = dc.dsreturn(ds, "Select ID,FullName,Mobile,DOB,Gender,Status from Family").Tables[0];
           dataGridView1.DataSource = bs;

My requirement is to update the datagridview with a button click. I need to use like this.
C#
adapter.Update(dataTable);

Problem is that, in the form i am not using any adapter object. My ultimate is to update the DB with Update Keyword
Posted
Comments
MohsenSaleh 4-Jan-15 14:58pm    
in the datagridveiw RowEndEditing event can write updating code
jinesh sam 4-Jan-15 15:06pm    
My question is how to make changes with DB. My datagridview is bounded with dataset. But there is no oledbadapter defined in the form. so i am not able to use adapter.Update(dataTable) method

1 solution

As you are already using a data adapter for getting your data, you can make that adapter a member variable of the form.

You can use this example from MSDN in order to create the select and update commands for the adapter.
OleDbDataAdapter.UpdateCommand Property[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900