I have an sqlite database which is displayed on a datagrid. I'm executing the query without any exceptions but the records are not deleted. I'm also having trouble to update the records too. any ideas? here is what I coded:
private void EraseRow_Click(object sender, RoutedEventArgs e)
{
_conn.Open();
SQLiteCommand cmd = new SQLiteCommand("Delete from Activity where RowID=5", _conn);
cmd.ExecuteNonQuery();
ActivitiesDataGrid.ItemsSource = _dataBase.updateDataGrid(_conn);
_conn.Close();
}
public ObservableCollection<Activity> updateDataGrid(SQLiteConnection _sqlConnect)
{
List<Activity> _actList = new List<Activity>();
SQLiteCommand cmd01 = new SQLiteCommand("SELECT * FROM Activity", _sqlConnect);
SQLiteDataReader reader = cmd01.ExecuteReader();
ObservableCollection<Activity> _activitiesList= new ObservableCollection<Activity>();
while (reader.Read())
{
Activity _act = new Activity();
_act.Name = reader.GetString(reader.GetOrdinal("Activity"));
_act.Customer = reader.GetString(reader.GetOrdinal("ActivityCustomer"));
string _actST = reader.GetString(reader.GetOrdinal("ActivityNature"));
_act.Activitytpe = (ActivityType)Enum.Parse(typeof(ActivityType), _actST);
string st = reader.GetString(reader.GetOrdinal("StartedAt"));
_act.StartedAt = Convert.ToDateTime(st);
string et = reader.GetString(reader.GetOrdinal("FinishedAt"));
_act.EndedAt = Convert.ToDateTime(et);
//string _ratio = reader.GetString(reader.GetOrdinal("ActivityRatio"));
//_act.ActivityRatio = Convert.ToDouble(_ratio);
_act.Notes = reader.GetString(reader.GetOrdinal("Notes"));
string _hldy = reader.GetString(reader.GetOrdinal("Holiday"));
_act.IsHoliday = Convert.ToBoolean(_hldy);
_activitiesList.Add(_act);
}
return _activitiesList;
//_adpt01.Fill(_tbl01);
//dgrid.ItemsSource = _tbl01.DefaultView;
//Disconnect(_sqlConnect);
}
Aucun commentaire:
Enregistrer un commentaire