web 2.0

VB.NET & System.Data.SqlClient - ExecuteScalar()

VB.NET & System.Data.SqlClient - ExecuteScalar() - How to learn Connector/NET ADO.NET component  System.Data.SqlClient namespace is the .NET Framework Data Provider for SQL Server 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 (SQL Server 2000,2005,2008 Database)

ShotDev Focus:
- VB.NET & System.Data.SqlClient - ExecuteScalar()



<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ 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 System.Data.SqlClient.SqlConnection
Dim objCmd As System.Data.SqlClient.SqlCommand
Dim strConnString,strSQL As String
Dim myScalar As Object

strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn = New System.Data.SqlClient.SqlConnection(strConnString)

strSQL = "SELECT MAX(Used) FROM customer"

objCmd = New System.Data.SqlClient.SqlCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With

myScalar = objCmd.ExecuteScalar()

objCmd = Nothing
objConn = Nothing

Return myScalar
End Function

<title>ShotDev.Com Tutorial</title>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="Server"></asp:Label>


VB.NET & System.Data.SqlClient - ExecuteScalar()
Download this script.

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.