Click here to Skip to main content
12,404,895 members (67,656 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 9-Jan-13 23:55pm
Comments
Member 9725940 10-Jan-13 6:00am
   
GroupId datatype Pls
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try this

SqlCommand cmd = new SqlCommand("select * from user_login where groupid='Student'", cnn);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

SqlCommand cmd = new SqlCommand("select * from user_login where groupid='Student'", cnn);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

If your Group_Id column datatype is varchar , then u must pass the value with in single codes dont forget this ....
select * from user_login where groupid='Student'
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
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);
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100