This is the code that I'm analyzing to understand, but there are several things that I don't understand...
PHP Code:
<%@ Page Language="C#" AutoEventWireup="False"
EnableSessionState="False" EnableViewState="False" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<script runat="server">
private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" +
"Server=localhost;Database=test;uid=root;pwd=yourpassword;option=3";
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
using(OdbcConnection con = new OdbcConnection(ConnStr))
using(OdbcCommand cmd = new OdbcCommand("SELECT * FROM Names", con))
{
con.Open();
dgrAllNames.DataSource = cmd.ExecuteReader(
CommandBehavior.CloseConnection |
CommandBehavior.SingleResult);
dgrAllNames.DataBind();
}
}
</script>
<html>
<head>
<title>Displaying Records from MySQL 'Names' table</title>
<style>
body { font: 100% Verdana; }
</style>
</head>
<body>
<p align="center">All records in the 'Names' table:</p>
<asp:DataGrid ID="dgrAllNames" HorizontalAlign="Center"
CellPadding="3" Runat="server" />
</body>
</html>
These lines:
PHP Code:
<script runat="server">
private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" +
"Server=localhost;Database=test;uid=root;pwd=yourpassword;option=3";
protected override void OnInit(EventArgs e)
{
base.OnInit(e); // what is base?
// this is really new, I thought we can use keyword "Using" at the top
// since it's similar to import in java right?
using(OdbcConnection con = new OdbcConnection(ConnStr))
using(OdbcCommand cmd = new OdbcCommand("SELECT * FROM Names", con))
{
con.Open(); // open connection
// full of mysteries
dgrAllNames.DataSource = cmd.ExecuteReader(
CommandBehavior.CloseConnection |
CommandBehavior.SingleResult);
dgrAllNames.DataBind();
}
}
</script>
but it's interesting!!! hope there's genius that can help me with this..
