Reference : http://www.stardeveloper.com/articles/display.html?article=2002041001&page=3



<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="C#" %>

<script runat="server">
 protected void Page_Load(Object sender, EventArgs e) {
  SqlConnection con = null;
  SqlCommand cmd = null;
  
  try {
   con = new SqlConnection("server=localhost;uid=sa;" + 
    "pwd=;database=Stardeveloper");
   cmd = new SqlCommand("SELECT * FROM Names", con);
   
   con.Open();
   grid.DataSource = cmd.ExecuteReader();
   grid.DataBind();

  } catch (Exception err) {
   message.Text = "<p><font color=\"red\">Err: " + 
    err.Message + "</font></p>";
  } finally {
   if(con != null)
    con.Close();
  }
 }
</script>

<html>
<head>
 <style>
 body { font-family:Verdana; font-size:12pt; }
 </style>
</head>
<body>
 <asp:datagrid id="grid" runat="server" />
 <asp:label id="message" runat="server" />
</body>
</html>