Click here to Skip to main content
15,884,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SqlCommand cmd = new SqlCommand("select * from user_login where groupid=Student", cnn);


in my user_login table groupid contains 3type date(Student,lecturer,admin)
I have to select data from user_login where groupid is Student .
but this query give error like : invalid collum name Student.
what is problem?
Posted
Comments
Tejal S 10-Jan-13 6:00am    
GroupId datatype Pls

try this

SQL
SqlCommand cmd = new SqlCommand("select * from user_login where groupid='Student'", cnn);
 
Share this answer
 
SqlCommand cmd = new SqlCommand("select * from user_login where groupid='Student'", cnn);


used Single '' code then execute this query



i hope your problem will solve if not please give your comment
 
Share this answer
 
C#
SqlCommand cmd = new SqlCommand("select * from user_login where groupid='Student'", cnn);
 
Share this answer
 
Hi,

If your Group_Id column datatype is varchar , then u must pass the value with in single codes dont forget this ....
SQL
select * from user_login where groupid='Student'
 
Share this answer
 
Hi Friend!!!
write your query like this...

SqlCommand cmd = new SqlCommand("select * from user_login where groupid='"Student"'", con);

or

SqlCommand cmd = new SqlCommand("select * from user_login where groupid='"+txtStudent.Text+"'", con); // if there you are reading value from textbox.


i hope it will help you
thanks
 
Share this answer
 
Comments
Faisalabadians 10-Jan-13 6:43am    
SqlCommand cmd = new SqlCommand("select * from user_login where groupid='"Student"'", con);


concatenation required here

string Student;
SqlCommand cmd = new SqlCommand("select * from user_login where groupid='" + Student + "'", con);

or if you dont want to concatenate, then it must be

SqlCommand cmd = new SqlCommand("select * from user_login where groupid='Student'", con);
can you tell what is the type of "groupid" column in your database? and if is the foreign key column or not? as the name of column is "groupid" I am suspecting that it would be in relation with some other table. if it is not, then all the solutions provided are correct.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900