codice:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim o As Object = RisultatoAggregazioneSQL(StringaConnessioneTest, "SELECT Max(Tabella1.ID) AS MaxDiID FROM Tabella1 ")
If o Is Nothing OrElse o Is DBNull.Value Then
Me.Label1.Text = "nessun valore presente"
Else
Me.Label1.Text = String.Format("il massimo valore è: {0}", o.ToString())
End If
End Sub
Public Function RisultatoAggregazioneSQL(ByVal StringaConnessione$, ByVal stringaSQL$) As Object
Dim Connessione As OleDbConnection = Nothing
Dim Comando As OleDbCommand = Nothing
Try
Connessione = New OleDbConnection(StringaConnessione)
Connessione.Open()
Comando = New OleDbCommand(stringaSQL, Connessione)
RisultatoAggregazioneSQL = Comando.ExecuteScalar()
Catch er As Exception
Throw
Finally
If Connessione IsNot Nothing Then Connessione.Close()
End Try
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>