Adyana Permatasari
Adyana Permatasari

Reputation: 157

SqlException unhandled on C# when trying to call a certain column on SQL Server 2008 R2

I have this code on C#

enter image description here

and I got NoIDStaffC from

NoIDStaffC = dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString();

Every time I try to run it, it keep telling me that SqlException was unhandled.

And this is my table in SQL Server :

enter image description here

Upvotes: 0

Views: 85

Answers (1)

mlorbetske
mlorbetske

Reputation: 5649

The problem you're seeing is because A002 isn't quoted in the query - so it's being treated as a column name instead of text to compare with.

You can either add single quotes around it in your built string or parameterize your query (preferred) to fix the problem.

Upvotes: 2

Related Questions