c#+database update according to datagrid

csharp , db Adelaide, Australia
  • 13 years ago

    hey frens,

    i have a datagridview and number of textboxes showing the value in the datgridrow clicked.

    now what i wan tis whenever change in textboxes or gridview happens, they must change their values accordingly.

    i m unable to update database:

    my code goes like this:

     

     OleDbConnection con = new OleDbConnection(@"provider= Microsoft.Jet.OLEDb.4.0; Data Source = D:\My Documents\Visual Studio 2005\Projects\db2.mdb");
                    con.Open();
    OleDbDataAdapter thisadapter1 = new OleDbDataAdapter("Select * from tbl_client where fname= '" + fname + "'", con);

    OleDbCommandBuilder cd = new OleDbCommandBuilder(thisadapter1);
                    DataSet ds = new DataSet();
    OleDbCommandBuilder builder= new OleDbCommandBuilder(thisadapter1);
                    thisadapter1.Fill(ds, "tbl_client");

     

     OleDbCommandBuilder mycommand = new OleDbCommandBuilder(thisadapter1);

                    int i = thisadapter1.Update(ds, "tbl_client");
                    if (i > 0)
                        {
                            MessageBox.Show("database updated");
                        }
                    else
                        {
                            MessageBox.Show("no updates");
                           
                        }
                   
                    con.Close();

     

     

    thanks in advance

    Radhika 

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson