I am developing C# without using any framework.until now i successfully performed following task on Datagrid.
1.Displaying data in Data-grid by binding with database table
2.Getting the selected row data from Data-grid based on primary key
Here is my variable declaration :
SQLiteDataAdapter adap;
SQLiteCommandBuilder cmdbl;
DataSet ds;
String Query;
DataTable dt;
Here is code for displaying data in Data-grid :
try
{
Query = "Select * from Items";
adap = new SQLiteDataAdapter(Query, GlobalVars.conn);
ds = new DataSet();
adap.Fill(ds, "Items");
dt = ds.Tables[0];
dtgitems.DataContext = ds.Tables[0].DefaultView;
dtgitems.ItemsSource = dt.DefaultView;
ds.Dispose();
adap.Dispose();
dt.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
It is working fine and here is my code for updating that data-grid
try
{
cmdbl = new SQLiteCommandBuilder(adap);
adap.Update(ds, "Items");
// ds.Tables[0].Clear();
}
catch (Exception ex)
{
}
it is not working .Does anyone knows how i can accomplish this update functionality in data-grid ? .Please help me to correct this code for update opreation .Thanks