繁体   English   中英

无效的列名异常,即使存在列也是如此

[英]invalid column name exception even though when column exists

当我尝试使用此查询访问数据库时,出现错误

invalid column name 'sandeep' which is the name of the patient ie itemArray[3]  

码:

case "patient":
string queryPatientCheck = @"select * 
                             from patient
                             where 
                             [patientID]={0} and
                             [patientName]={1}";

queryPatientCheck = string.Format(queryPatientCheck, itemArray[2], itemArray[3]);

好你的SQL翻译成这个

select * 
                             from patient
                             where 
                             [patientID]={0} and
                             [patientName]=sandeep

在这种情况下,它将搜索名为sandeep的列。 您想要的是字符串sandeep,即'sandeep'

select * 
                             from patient
                             where 
                             [patientID]={0} and
                             [patientName]='sandeep'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM