Chapter 03 first and second example, although i typed the code exactly the same from book, in both cases, i can only see the heading with <h3>. the rest of the table can't be seen in both examples. Then, I replace the files with the one from download code, the same problem. Is it my connection error or what? I put the code as follows.
First Example
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Beginning ASP.NET Databases Using C#: Chapter 3</title>
</head>
<body>
<h4>First Example: Listing data from the Employees table</h4>
<asp:DataGrid id="dgNameList"
runat="server"
GridLines="None"
BackColor="LightBlue"
CellPadding="5"
CellSpacing="5"
BorderWidth="2"
BorderColor="Black"
ToolTip="Includes only those employees who are at HQ" />
</body>
</html>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
String strConnection = "server=(local)\\NetSDK; database=Northwind; integrated security=true;";
SqlConnection objConnection = new SqlConnection(strConnection);
String strSQL = "SELECT FirstName, LastName, Country " + "FROM Employees";
SqlCommand objCommand = new SqlCommand(strSQL, objConnection);
objConnection.Open();
dgNameList.DataSource = objCommand.ExecuteReader();
dgNameList.DataBind();
objConnection.Close();
}
</script>
-----------------------------------------------------------------------------------
Second Example
..............
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>
<html>
<head>
<title>Connecting to an Access Database</title>
</head>
<body>
<H3>Connecting to an Access Database</H3>
<asp:DataGrid id="dgSuppliers" runat="server" />
</body>
</html>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
String strConnection = "Provider=Microsoft.Jet.OleDb.4.0; data source=C:\\7418BegASPNETdbCS\\datastores\\Northwin d.mdb;";
OleDbConnection objConnection = new OleDbConnection(strConnection);
String strSQL = "SELECT SupplierID, CompanyName FROM Suppliers";
OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);
objConnection.Open();
dgSuppliers.DataSource = objCommand.ExecuteReader();
dgSuppliers.DataBind();
objConnection.Close();
}
</script>
|