vb.net 计算mysql表中的行数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20478022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:05:03  来源:igfitidea点击:

Counting rows in mysql table

mysqlsqlvb.netvisual-studio-2010

提问by Bradley

I was wondering how I could count the number of rows in a MySql database using vb.net (as an integer) It's quite a simple question as I am quite nooby with MySql and vb.net.

我想知道如何使用 vb.net(作为整数)计算 MySql 数据库中的行数这是一个非常简单的问题,因为我对 MySql 和 vb.net 很不友好。

回答by Rahul Tripathi

Try this

尝试这个

SELECT COUNT(*) FROM YOURTABLENAME

In VB.NET you can try like this:

在 VB.NET 中,您可以这样尝试:

Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click

        Dim con As New MySqlConnection(cnString)
        con.Open()
        Dim cmd As New MySqlCommand("SELECT COUNT(*) FROM YOURTABLENAME ", con)
        Dim i As Integer = cmd.ExecuteScalar()
        cmd = Nothing
        con.Close()
        txt_count.Text = i

End Sub

回答by Bradley

SELECT COUNT(*) FROM TABLENAME

从表名中选择 COUNT(*)