I have virtual dataGridView which displays all values in table by Just-In-Time method documentation here. My view has more computed columns, so I use it only to show data and then only delete by single SQLCommand. The problem comes when I am executing the delete command. When I execute it, it throws error
Conversion failed when converting the nvarchar value 'TextValueFromThirdColumn' to data type int.
xxx is not ID, but computed data in third column.
using(SqlConnection c = new SqlConnection(Properties.Settings.Default.ConnectionString))
{
c.Open();
SqlCommand command = new SqlCommand("delete from entryTable where ID = @id", c);
command.Parameters.AddWithValue("@id", dataGridView1.SelectedRows[0].Cells["ID"].Value.ToString());
command.ExecuteNonQuery();
}
As you can see I am building query with parameter which adds just fine, but the error thrown seems inadequate for me, because third column has nothing to do with my ID column. Thanks in advance for any advice