user2694605
user2694605

Reputation:

Counting rows in mysql table

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.

Upvotes: 0

Views: 7324

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

Try this

SELECT COUNT(*) FROM YOURTABLENAME

In VB.NET you can try like this:

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

Upvotes: 3

Bradley
Bradley

Reputation: 2141

SELECT COUNT(*) FROM TABLENAME

Upvotes: 1

Related Questions