Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: beg ASP.NET with C# - Errors when trying example on pg 490.


Message #1 by "dave" <dougwood@a...> on Tue, 17 Sep 2002 18:25:50
Hey,
I am having problems with the "Try It Out" on pg 490 , ADO.NET SqlClient 
Objects.

I have installed a version of SQL Server on my computer, and the 
Northwind.mdb database is in C:\BegASPNET\Ch12 folder. (Is that all I need 
to do to get SQL Server to connect to this database?. There is absolutely 
no documentation in this book about how to do this)

Anyway, my code is:

<%@Page Language="C#"%>
<% Import Namespace="System.Data" %>
<% Import Namespace="System.Data.SqlClient" %>
<html>
<head>
	<title>Untitled</title>
</head>
<body>
<h2>display of data in a table using SQL objects</h2>
<asp:datagrid id="dgrEmployees" runat="server" />
<script language="c#" runat="server">
void Page_Load()
{
	string strSQL = "SELECT FirstName, LastName FROM Employees;";
	string strConnection = "server=DOUGEFRESH;"; //my server name
	strConnection += "database=Northwind;uid=sa;password=;";
	DataSet objDataSet = new DataSet();
	SqlConnection objConnection = new SqlConnection(strConnection);
	
	SqlDataAdapter objDataAdapter = new SqlDataAdapter(strSQL, 
objConnection);
	
	objDataAdapter.Fill(objDataSet, "Employees");
	
	DataView objDataView = new DataView(objDataSet.Tables
["Employees"]);
	//assign the dataview object to the datagrid control
	dgrEmployees.DataSource = objDataView;
	dgrEmployees.DataBind(); 
	}
	</script>
</body>
</html>


Now my error message says
Compiler Error Message: CS0246: The type or namespace name 'DataSet' could 
not be found (are you missing a using directive or an assembly reference?)

when i expand the error message:

The type or namespace name 'DataSet' could not be found (are you missing a 
using directive or an assembly reference?)
The type or namespace name 'SqlConnection' could not be found (are you 
missing a using directive or an assembly reference?)
The type or namespace name 'SqlDataAdapter' could not be found (are you 
missing a using directive or an assembly reference?)
The name 'objDataSet' does not exist in the class or 
namespace 'ASP.hs_dataTableUsingSQL_aspx'
The type or namespace name 'objDataAdapter' could not be found (are you 
missing a using directive or an assembly reference?)
The type or namespace name 'DataView' could not be found (are you missing 
a using directive or an assembly reference?)

Please help!!!!
thanks!

Doug
Message #2 by "dave" <dougwood@a...> on Wed, 18 Sep 2002 08:15:53
Never mind, I figured it out!!!

  Return to Index