开发者

CommandText Property has not been initialized

开发者 https://www.devze.com 2022-12-17 02:38 出处:网络
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 be

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消