Torna al Thread

<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Dim Conn As String = ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString Dim MyConnection As SqlConnection = New SqlConnection(Conn) Dim SQL As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) MyConnection.Open() SQL = "SELECT * FROM utenti" Dim cmd As New SqlCommand(SQL, MyConnection) Dim rdr As SqlDataReader = cmd.ExecuteReader() While rdr.Read Dim numrows As Integer Dim numcells As Integer Dim i As Integer Dim j As Integer Dim r As TableRow Dim c As TableCell ' Generate rows and cells numrows = 2 numcells = 5 For j = 0 To numrows - 1 r = New TableRow() For i = 0 To numcells - 1 c = New TableCell() c.Controls.Add(New LiteralControl("" & rdr("username") & "")) r.Cells.Add(c) Next i Table1.Rows.Add(r) Next j End While MyConnection.Close() End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Table id="Table1" Font-Names="Verdana" Font-Size="8pt" CellPadding=5 CellSpacing=0 BorderColor="black" BorderWidth="1" Gridlines="Both" runat="server"/> </div> </form> </body> </html>
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5