选择count(*)语句 [英] select count(*) statement

查看:210
本文介绍了选择count(*)语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在计算来自mySql数据库的记录数时出现问题:

Having a problem counting number of record from mySql database:

adpter = New MySqlDataAdapter("select count(*) from bookings where busNumber = '" & txtBusNumber.Text & "' and departTime = '" & cmbDepartTime.Text & "' and departDay = '" & cmbDay.Text & "'", con)
        Dim myDataSet = New DataSet
        adpter.Fill(myDataSet, "bookings")
        

        txtCount.Text = myDataSet.Tables("bookings").Rows(0).Item(0)


我得到0 ...

请帮助


I get 0...

please Help

推荐答案

检查您的数据库,看看您是否真的有任何设置过滤条件的记录.从查询中可以清楚地看到所有过滤器字段都为varchar,因此查询似乎还可以.

一些优化点,
您最好使用参数化查询.这不是必须的要求,但始终是可取的.

我知道,您使用数据集来获取计数值.这将占用更多资源.因此,我建议您使用ExecuteScalar.

欢呼
Check your database and see, if you really have any records for the filter criteria you set. From the query, it is clear that you have all the filter fields as varchar, so the query seems okay.

Some optimization point,
You better use parameterized query. This is not a must requirement but always advisable.

I see, you use a dataset to get the count value. This will take more resource. So, I suggest, you use ExecuteScalar.

cheers


这篇关于选择count(*)语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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