VB.NET & MySql.Data.MySQLClient - ExecuteScalar() - How to learn Connector/NET ADO.NET component MySql.Data.MySqlClient namespace is the .NET Framework Data Provider for MySql data source, Using the ExecuteScalar method for Executes the query, and returns the first column of the first row in the result set returned by the query (MySQL Server Database)
ShotDev Focus:
- VB.NET & MySql.Data.MySQLClient - ExecuteScalar()
Example
ExecuteScalar.aspx
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="MySql.Data.MySqlClient"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Dim myValue As Object myValue = exExecuteScalar() lblText.Text = myValue.ToString() End Sub Function exExecuteScalar() As Object Dim objConn As MySql.Data.MySqlClient.MySqlConnection Dim objCmd As MySql.Data.MySqlClient.MySqlCommand Dim strConnString,strSQL As String Dim myScalar As Object strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false" objConn = New MySql.Data.MySqlClient.MySqlConnection(strConnString) objConn.Open() strSQL = "SELECT MAX(Used) FROM customer" objCmd = New MySql.Data.MySqlClient.MySqlCommand() With objCmd .Connection = objConn .CommandType = CommandType.Text .CommandText = strSQL End With myScalar = objCmd.ExecuteScalar() objCmd = Nothing objConn.Close() objConn.Close() objConn = Nothing Return myScalar End Function </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="Server"></asp:Label> </form> </body> </html>
Screenshot