I am trying to get the the number of rows that are populated in a SQL Server table. I am using the code below but it only counts one row everytime when I know in fact that there are 47 row in a particular table. Could someone please point out what I am doing wrong?
Dim connetionString As String Dim connection As SqlConnection Dim command As SqlCommand Dim adapter As New SqlDataAdapter Dim ds As New DataSet Dim sql As String connetionString = ("SERVER=x.x.x.x;database=ITDatabase;trusted_connection=yes;") sql = ("SELECT COUNT(*)FROM ASSETINFO;") connection = New SqlConnection(connetionString) Try connection.Open() command = New SqlCommand(sql, connection) adapter.SelectCommand = command adapter.Fill(ds, "SQLTempTable") lbltotalAssetsinDatabase.Text = ds.Tables(0).Rows.Count adapter.Dispose() command.Dispose() connection.Close() Catch ex As Exception MsgBox("Can not open connection ! ") End Try
Edited 6 Months Ago by lmalave