如何使用VB.Net计算SQL表中的项目数? [英] How to count the number of items in SQL Table with VB.Net?

查看:76
本文介绍了如何使用VB.Net计算SQL表中的项目数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何查找表中条件的行数。



ex: - 从员工中选择计数(EmployeeName),其中group ='&Trim(Combobox1.text)&'



这不是给出在组合框中指定的组的员工数量。



请帮助



谢谢

解决方案

< blockquote>

  SELECT 计数(*) AS  EmpCount FROM employee where group = ' & Combobox1.SelectedItem.ToString()&' 





组合框令人困惑,.Text属性可能不是实际选择的,所以使用SelectedItem.SelectedItem是一个对象,所以你必须将它转换为字符串。



另请注意,SQL中的=操作区分大小写,因此如果情况不完全匹配,则计数将不正确。做一个不区分大小写的搜索,使用LIKE。



BTW,(正如我的评论所说)你应该学习SQL注入攻击,以及如何在SQL中使用参数避免它们的语句。


将combo.text更改为combo.selec teditem

Hi all,

How to find the number of items in a row for a condition in table.

ex:- "select count(EmployeeName) from employee where group = '"& Trim(Combobox1.text) &"'"

this is not giving the number of employees with group specified in combo box.

please help

Thanks

解决方案

SELECT Count(*) AS EmpCount FROM employee where group = '" & Combobox1.SelectedItem.ToString() & "'"



Comboboxes are confusing, the .Text property may not be what is actually selected, so use the SelectedItem. SelectedItem is an object so you have to convert it to a string.

Also note that the "=" operation in SQL is case sensitive, so if the case does not match exactly, then the count will not be right. To do a case insensitive search, use "LIKE".

BTW, (as my comment says) you should learn about SQL injection attacks, and how to use parameters in SQL statements to avoid them.


change that combo.text to combo.selecteditem


这篇关于如何使用VB.Net计算SQL表中的项目数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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