I am trying to create a simple windows form to
- Display all data from SQLite table (Completed)
- Display data in grid view and make the grid editable(Completed) (I marked the Grid view as editable in Windows Form)
- Insert/Update/Delete the data in SQLite table based on the changes in grid view. (Problem!). I tried to set the Insert/Update/Delete using SQLiteCommandBuilder but nothing worked :(
Thanks in advance.
FillData is used to populate the in Grid view and updatechanges click should be insert/update/delete from SQLLite based on the changes in grid view.
private void FillData()
{
SQLiteConnection conn = new SQLiteConnection(objLogic.dbConnection);
dtReviewers.AutoGenerateColumns = true;
string selectCommand = "SELECT * FROM Student";
da = new SQLiteDataAdapter(selectCommand, conn);
conn.Open();
ds = new DataSet();
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(da);
da.Fill(ds, "Design1");
dtReviewers.DataSource = ds.Tables[0];
//dtReviewers.DataMember = "Design1";
}
private void UpdateChanges_Click(object sender, EventArgs e)
{
SQLiteConnection conn = new SQLiteConnection(objLogic.dbConnection);
try
{
dtReviewers.EndEdit();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ds.Tables[0].Rows[i].AcceptChanges();
//if (dtReviewers.Rows[i].RowState == DataRowState.Modified)
//{
ds.Tables[0].Rows[i].SetModified();
//}
}
// SQLiteCommandBuilder oBuilder = new SQLiteCommandBuilder(da);
// da.UpdateCommand = oBuilder.GetUpdateCommand();
//da.AcceptChangesDuringUpdate = true;
da.Update(ds.Tables[0]);
ds.AcceptChanges();
conn.Close();
}
catch (Exception ex)
{
throw ex;
}
}
Aucun commentaire:
Enregistrer un commentaire