0

当我尝试使用此查询访问数据库时,它给了我一个错误

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]);
4

1 回答 1

3

那么你的sql翻译成这个

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

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

select * 
                             from patient
                             where 
                             [patientID]={0} and
                             [patientName]='sandeep'
于 2012-07-31T06:46:11.120 回答