[英]SqlException unhandled on C# when trying to call a certain column on SQL Server 2008 R2
I have this code on C# 我在C#上有这个代码
and I got NoIDStaffC from 我得到了NoIDStaffC
NoIDStaffC = dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString();
Every time I try to run it, it keep telling me that SqlException
was unhandled. 每次我尝试运行它时,它都会告诉我
SqlException
未处理。
And this is my table in SQL Server : 这是我在SQL Server中的表:
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. 您看到的问题是因为查询中未引用
A002
- 所以它被视为列名而不是要与之比较的文本。
You can either add single quotes around it in your built string or parameterize your query (preferred) to fix the problem. 您可以在构建的字符串中添加单引号或参数化查询 (首选)以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.