Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write where condition in asp.net c#
----------------------------------------

This is my code, it shows error

C#
SqlCommand cmd = new SqlCommand("Select count(*) from Equipments where EquipmentType = CPU", Con);


I want to display all CPU records please help.

Thanks
Posted
Updated 22-Apr-14 0:30am
v2
Comments
abhishek_singh 22-Apr-14 5:08am    
what is problem in this statement?

you can try this one for all record on CPU EquipmentType ...
Quote:
SqlCommand cmd = new SqlCommand("Select * from Equipments where EquipmentType = 'CPU' ", Con);
 
Share this answer
 
That query will only return one record - indeed only one value - even when fixed, because it returns the number of rows that match the condition, not the actual rows themselves.
To make the WHERE work, you need to tell SQL that CPU is a string (assuming it is):
C#
SqlCommand cmd = new SqlCommand("Select count(*) from Equipments where EquipmentType = 'CPU'", Con);

But to return the actual records:
C#
SqlCommand cmd = new SqlCommand("Select * from Equipments where EquipmentType = 'CPU'", Con);
 
Share this answer
 

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