Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

SqlClient DataGrid - << VERSIONE C# >>


Popolare un DataGrid utilizzando SqlClient


<%@ Page language="VB" Debug="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<script language="vbscript" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim myConn As SqlConnection = New SqlConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & _
    Server.MapPath("database/utenti.mdb"))
  Dim myCmd As SqlCommand = New SqlCommand("select nome, cognome, email from utenti", myConn)
  Try
    myConn.Open()
    myGrid.DataSource = myCmd.ExecuteReader()
    myGrid.DataBind()
  Finally
    myConn.Close()
  End Try
End Sub
</script>
<body>
<asp:datagrid id="myGrid" runat="server"
width="92%" cellpadding=5 font-size="8pt"
gridlines="horizontal"
headerstyle-backcolor="slategray"
headerstyle-forecolor="ivory"
itemstyle-verticalalign="top"
autogeneratecolumns=false>
<columns>
<asp:boundcolumn headertext="Nome"
datafield="Nome" />
<asp:boundcolumn headertext="Cognome"
datafield="Cognome" />
<asp:boundcolumn headertext="Email"
datafield="Email" />
</columns>
</asp:datagrid>
</body>
</html>



Scarica il Codice...


Stampa la pagina


 








Inizio pagina

risorse per webmaster