CommandText Property has not been initialized
The following code attempts to delete a selected row from a datagridview and update the database.
But it's not updating the database...it's just issuing the error, "CommandText Property has not been initialized." ...any ideas? I assume it's because it's not being bound in the beginning, but at this point I'm clueless and my head is sore.
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.tra开发者_运维知识库desTableAdapter.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
}
}
I deleted my table adapters, datasets, etc... and recreated the entire table. Populated it with new data, and tried to delete a row. It worked... Don't know why, but it works now.
精彩评论