namespace
Jeg har et begynderproblem med ASP.NET - hjælp mig eksperter!!Benytter følgende kode i main.aspx:
<%@ Page Language="C#" ClientTarget="Downlevel" Src="SystemController.cs" Debug="True" %>
<%@ import Namespace="Controller" Inherits="SystemController" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
// Databind the data grid on the first request only
// (on postback, bind only in editing, paging and sorting commands)
SystemController sc = new SystemController();
// sc.MyQueryMethod()
// myCommand.Fill(ds);
DataGrid1.DataSource = sc.MyQueryMethod();
DataGrid1.DataBind();
}
}
</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Data from database
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" AllowPaging="True" PageSize="6" OnPageIndexChanged="DataGrid_Page" BackColor="White" CellPadding="4" width="80%" OnLoad="Page_Load" BorderStyle="None" BorderWidth="1px" BorderColor="#3366CC"></asp:datagrid>
</form>
</body>
</html>
SystemController.cs:
using System;
using System.Data;
using System.Data.SqlClient;
// using DbHandler;
public class SystemController{
private DbHandler db;
public SystemController(){
db = new DbHandler("server=(local);database=TestDb;trusted_connection=true");
}
public DataSet MyQueryMethod() {
return db.MyQueryMethod();
}
}
DbHandler.cs:
using System;
using System.Data;
using System.Data.SqlClient;
// using Controller;
public class DbHandler {
private String connection;
public DbHandler() {
conncetion = null;
}
public DbHandler(String _connection) {
this.connection = connection;
SqlConnection myConnection = new SqlConnection(connection);
}
public System.Data.DataSet MyQueryMethod() {
string connectionString = "server=\'localhost\'; trusted_connection=true; Database=\'TestDb\'";
System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);
string queryString = "SELECT [Kunde].[au_id], [Kunde].[au_lname], [Kunde].[au_fname] FROM [Kunde]";
System.Data.SqlClient.SqlCommand sqlCommand = new System.Data.SqlClient.SqlCommand(queryString, sqlConnection);
System.Data.SqlClient.SqlDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter(sqlCommand);
System.Data.DataSet dataSet = new System.Data.DataSet();
dataAdapter.Fill(dataSet);
return dataSet;
}
}
Men ved kompilering fås følgende trace:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'DbHandler' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 7: public class SystemController{
Line 8:
Line 9: private DbHandler db;
Line 10:
Line 11: public SystemController(){
Source File: SystemController.cs Line: 9
HILFE BITTE!
