Click here to Skip to main content
Rate this: bad
good
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 at 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 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 at 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
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  

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

  Print Answers RSS
0 OriginalGriff 318
1 Richard Deeming 180
2 Sergey Alexandrovich Kryukov 175
3 Yogesh Kumar Tyagi 165
4 ChauhanAjay 156
0 Sergey Alexandrovich Kryukov 6,218
1 OriginalGriff 5,413
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
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