views:

174

answers:

1

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.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
        }
A: 

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.

Woody
It works because you now has a command assigned to the UpdateCommand property of the DataAdapter.
AMissico