Smita

Smita

  • NA
  • 3
  • 0

Unable to update database from datagridview

Aug 11 2010 4:58 PM
Hi ,

I am trying to update database through datagridview, its neither throwing any error nor updating the database.

SQLiteConnection con = new SQLiteConnection(@"data source=C:\SQLiteDB\Test.sqlite");
        SQLiteCommand Cmd = new SQLiteCommand() ;
        SQLiteDataAdapter ad = new SQLiteDataAdapter();
        DataSet ds = new DataSet();
        DataRow dr;
        DataTable dt = new DataTable();
        SQLiteCommandBuilder bd;
        SQLiteCommandBuilder cb;

form_load
{

 con.Open();
                    SQLiteCommand Cmd = con.CreateCommand();
                    Cmd.CommandText = "select * from SqliteSmithaTbl";
                    SQLiteDataAdapter ad = new SQLiteDataAdapter(Cmd.CommandText, con);

                    ad.Fill(ds, "test");
                    //ad.Fill(dt);

                    cb = new SQLiteCommandBuilder(ad);
                    BindingSource bSource = new BindingSource();


                    bSource.DataSource = ds.Tables["test"];
                    dataGridView1.DataSource = bSource;
                    


}

  button click event       
{
cb.RefreshSchema();
           dataGridView1.EndEdit();
           ad.AcceptChangesDuringUpdate = true;
           ds.AcceptChanges();
 
           ad.UpdateCommand = cb.GetUpdateCommand();
           ad.InsertCommand = cb.GetInsertCommand();
           //ad.DeleteCommand = cb.GetDeleteCommand();

           ad.Update(ds.Tables["test"]);
           ad.Dispose();
           con.Close();

}

Please help..........!!

Answers (1)