How To Execute MySQL Database Count Max Min Avg In VbNet
In This VB.Net Tutorial We Will See How To Use MySQL ExecuteScalar Function To:
- execute count command to get database table's records count.
- execute min command to get database minimum value.
- execute max command to get database maximum value.
- execute avg command to get database average value.
In Visual Basic.Net Programming Language And Visual Studio Editor.
- execute count command to get database table's records count.
- execute min command to get database minimum value.
- execute max command to get database maximum value.
- execute avg command to get database average value.
In Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Imports MySql.Data.MySqlClient
Public Class vbnet_mysql_ExecuteScalar
Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=s_t_d")
' button count
Private Sub Button_Count_Click(sender As Object, e As EventArgs) Handles Button_Count.Click
Dim command As New MySqlCommand("SELECT COUNT(`Id`) FROM `student`", connection)
connection.Open()
LabelVAL.Text = command.ExecuteScalar().ToString()
connection.Close()
End Sub
' button avg
Private Sub Button_AVG_Click(sender As Object, e As EventArgs) Handles Button_AVG.Click
Dim command As New MySqlCommand("SELECT AVG(`Id`) FROM `student`", connection)
connection.Open()
LabelVAL.Text = command.ExecuteScalar().ToString()
connection.Close()
End Sub
' button max
Private Sub Button_MAX_Click(sender As Object, e As EventArgs) Handles Button_MAX.Click
Dim command As New MySqlCommand("SELECT MAX(`Id`) FROM `student`", connection)
connection.Open()
LabelVAL.Text = command.ExecuteScalar().ToString()
connection.Close()
End Sub
' button min
Private Sub Button_MIN_Click(sender As Object, e As EventArgs) Handles Button_MIN.Click
Dim command As New MySqlCommand("SELECT MIN(`Id`) FROM `student`", connection)
connection.Open()
LabelVAL.Text = command.ExecuteScalar().ToString()
connection.Close()
End Sub
End Class
///////////////OUTPUT:
Post A Comment:
0 comments: