Programmazione Web » Asp.NET » Contare i record di un database Sql Server
Contare i record di un database Sql Server
Difficoltà:
Scritto da Andrea Benaglio
Sito Web: http://www.dotnetit.com ![]()
Questo tutorial è stato letto 1109 volte
In questo esempio viene descritto come contare i records presenti in una specifica tabella di un Data Base SQL Server; verrà utilizzato un comando SQL per eseguire la query nella tabella "Products".
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim objCon As New SQLConnection("server=localhost;User id=SA;password=;database=Northwind")
Dim cmd As SQLCommand = New SQLCommand("Select count(*) from Products", objCon)
objCon.Open()
response.write (cmd.ExecuteScalar().toString )
end sub
</script>

