如何使用Select语句在asp.net c#中写入where条件 [英] How to write where condition in asp.net c# using Select statement

查看:64
本文介绍了如何使用Select语句在asp.net c#中写入where条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中写出条件c#

----------------------------- -----------



这是我的代码,显示错误



 SqlCommand cmd =  new  SqlCommand( 从Equipments中选择count(*),其中EquipmentType = CPU,Con); 





我想显示所有CPU记录,请帮助。



谢谢

解决方案

你可以尝试这个用于CPU EquipmentType上的所有记录...

Quote:

SqlCommand cmd = new SqlCommand(Select * from Equipments where EquipmentType ='CPU',Con);


< blockquote>该查询只会返回一条记录 - 实际上只有一个值 - 即使是固定的,因为它返回的条件符合条件,而不是实际的行本身。

使WHERE工作,你需要告诉SQL CPU是一个字符串(假设是):

 SqlCommand cmd =  new  SqlCommand( 从Equipments中选择count(*),其中EquipmentType ='CPU',Con); 



但要返回实际记录:

 SqlCommand cmd =  new  SqlCommand( 从Equipments中选择*,其中EquipmentType ='CPU',Con); 


How to write where condition in asp.net c#
----------------------------------------

This is my code, it shows error

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



I want to display all CPU records please help.

Thanks

解决方案

you can try this one for all record on CPU EquipmentType ...

Quote:

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


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):

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


But to return the actual records:

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


这篇关于如何使用Select语句在asp.net c#中写入where条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆