-1

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();
     }

added parameter

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

Hynek Bernard
  • 744
  • 1
  • 11
  • 30

1 Answers1

0

Okay, It was my dumb fault. This is problem with trigger on SQL server. I did not realize I made changes to database layout and trigger stopped working because it inserted values into wrong column. The error code showed what happened with trigger, not with row.

Hynek Bernard
  • 744
  • 1
  • 11
  • 30