Get number of rows in a SQL Server table in VB.NET

前端 未结 3 1225
太阳男子
太阳男子 2021-01-13 01:16

There are 10 rows in primary_student_table.

When I execute the following code, the result was -1.

Dim count As Int16
con.Open()
query =          


        
3条回答
  •  没有蜡笔的小新
    2021-01-13 02:05

        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString = "server=localhost;userid=root;password=1234;database=dblms"
        Dim READER As MySqlDataReader
    
        Try
            MysqlConn.Open()
            Dim Query As String
    
            Query = "Select * from dblms.accounts"
            COMMAND = New MySqlCommand(Query, MysqlConn)
            READER = COMMAND.ExecuteReader
            Dim count As Integer
            count = 0
            While READER.Read
                count = count + 1
    
            End While
          MysqlConn.Close()
    
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            MysqlConn.Dispose()
    
        End Try
    

    the value in count will be the number of rows in a table :) hope this helped

提交回复
热议问题