Следующий код пытается удалить выбранную строку из datagridview и обновить базу данных.
Но он не обновляет базу данных... он просто выдает ошибку "Свойство CommandText не было инициализировано". ...есть идеи? Я предполагаю, что это потому, что он не был связан в начале, но в этот момент я ничего не знаю, и у меня болит голова.
private void deleteRow()
{
DialogResult dr = MessageBox.Show("Are you sure you want to delete this row?", "Confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
while (dataGridView1.SelectedRows.Count > 0)
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
try
{
this.Validate();
this.tradesBindingSource.EndEdit();
this.tradesTableAdapter.Update(this.tradesDataSet.Trades);
}
catch (Exception ex)
{
MessageBox.Show("An error occurred during the update process: " + ex);
// Add code to handle error here.
}
this.tradesTableAdapter.Fill(this.tradesDataSet.Trades); // refresh table
}
}