0% found this document useful (0 votes)
34 views

Display Number of Records in SQL SERVER

This code handles a button click event that retrieves data from a SQL database table and displays the row count on a label. It opens a connection to the database, executes a SELECT query on the Users table, fills a dataset, and displays the row count from the result before closing the connection.

Uploaded by

Horizon 99
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Display Number of Records in SQL SERVER

This code handles a button click event that retrieves data from a SQL database table and displays the row count on a label. It opens a connection to the database, executes a SELECT query on the Users table, fills a dataset, and displays the row count from the result before closing the connection.

Uploaded by

Horizon 99
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Private Sub Button1_Click(sender As System.Object, e As System.

EventArgs)
Handles Button1.Click
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= DESKTOP-5ADB7M6; Database = CAMRI_DB;Integrated


Security = true")
sql = ("SELECT * FROM Users")
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
End Sub

You might also like