简体   繁体   English

尝试在SQL Server 2008 R2上调用某个列时,在C#上未处理SqlException

[英]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.

相关问题 使用C#安装SQL Server 2008 R2 Express - Install SQL Server 2008 R2 Express using C# 具有现有SQL Server 2008 R2数据库的C#应用 - C# App with Existing SQL Server 2008 R2 Database 尝试连接到SQL Server数据库时出现“ SqlException未处理”错误 - 'SqlException was unhandled' error when trying to connect to SQL Server database 进行设置以使用C#连接到SQL Server 2008 R2中的服务器 - Make a setting to connect to server in SQL Server 2008 R2 using C# 如何从SQL Server 2008 R2-终结点调用网络方法? - How to call a webmethod from SQL Server 2008 R2 - endpoint? C#代码,用于为插入SQL Server 2008 R2的每一行生成唯一ID - C# Code for generating Unique ID for each row inserted into SQL Server 2008 R2 C#SQL Server 2008 R2插入存储过程将不起作用 - C# sql server 2008 r2 insert stored procedure won't work 如何通过网络从C#ClickOnce应用程序访问SQL Server 2008 R2 - How to access sql server 2008 R2 from C# ClickOnce application over a network 适用于Microsoft SQL Server Express 2008 R2的VS C#constring - VS C# constring for Microsoft SQL Server Express 2008 R2 如何使用C#在SQL Server 2008 R2中拆分和存储XML? - How to split and store XML in SQL Server 2008 R2 using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM