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 - << VB.NET VERSION >>


Pupulate a DataGrid using SqlClient


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e )
{
  SqlConnection myConn = new SqlConnection(
  ConfigurationSettings.AppSettings["MyDatabase"]);
  SqlCommand myCmd = new SqlCommand("select Nome, Cognome, Email from utenti", myConn);
  try
  {
    myConn.Open();
    myGrid.DataSource = myCmd.ExecuteReader();
    myGrid.DataBind();
    myConn.Close ( );
  }
  finally
  {
    myConn.Close();
  }
}
</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>



Download Code...


Print Page


 








Page top

risorse per webmaster