user1550164
user1550164

Reputation: 1

invalid column name exception even though when column exists

when I try to access the database with this query it gives me an error

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

code:

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

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

Upvotes: 0

Views: 578

Answers (1)

Baz1nga
Baz1nga

Reputation: 15579

well your sql translates to this

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

and in this case it searches for a column called sandeep. What you want is the string sandeep i.e 'sandeep'

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

Upvotes: 3

Related Questions