×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

懂ASP.NET的请进。会者不难,难者不会,急死我了,快帮忙啊。

本文发表在 rolia.net 枫下论坛我有一个business class - DataLayer.cs,内容见下边:

using System;
using System.Data;
using System.Data.OleDb;
using System.Web;

namespace SystemOne.NET
{
public class DataLayer
{
private OleDbConnection getConnection()
{
String cnString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" + Server.MapPath("db1.mdb");
return new OleDbConnection(cnString);
}
public DataLayer()
{
}
public DataView getSites()
{
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from Sites", getConnection());

DataSet ds = new DataSet();
myCommand.Fill(ds, "Sites");
return ds.Tables["Sites"].DefaultView;
}
public DataView getPreferredVendors()
{
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from Site_Trade_Join", getConnection());

DataSet ds = new DataSet();
myCommand.Fill(ds, "Site_Trade_Join");
return ds.Tables["Site_Trade_Join"].DefaultView;
}
}
}

可我编译的时候,出错如下:[C# Error] DataLayer.cs(15): The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)

我觉得太奇怪了,既然Server 是个built-in object,怎么我的编译器就不认识呢?谢谢高手!!更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 懂ASP.NET的请进。会者不难,难者不会,急死我了,快帮忙啊。
    本文发表在 rolia.net 枫下论坛我有一个business class - DataLayer.cs,内容见下边:

    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.Web;

    namespace SystemOne.NET
    {
    public class DataLayer
    {
    private OleDbConnection getConnection()
    {
    String cnString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" + Server.MapPath("db1.mdb");
    return new OleDbConnection(cnString);
    }
    public DataLayer()
    {
    }
    public DataView getSites()
    {
    OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from Sites", getConnection());

    DataSet ds = new DataSet();
    myCommand.Fill(ds, "Sites");
    return ds.Tables["Sites"].DefaultView;
    }
    public DataView getPreferredVendors()
    {
    OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from Site_Trade_Join", getConnection());

    DataSet ds = new DataSet();
    myCommand.Fill(ds, "Site_Trade_Join");
    return ds.Tables["Site_Trade_Join"].DefaultView;
    }
    }
    }

    可我编译的时候,出错如下:[C# Error] DataLayer.cs(15): The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)

    我觉得太奇怪了,既然Server 是个built-in object,怎么我的编译器就不认识呢?谢谢高手!!更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • try to add 'using System.IO;' at the top.
      • 不行啊,还是报的同样的错,5555
        • 我记错了,server不是system.IO里面的。
    • try: HttpContext.Current.Server.MapPath("db1.mdb");
      • 真的行了啊,救命恩人啊!!我能看懂你这个,可我不知道我那个错在哪里:(
        • 少引用了system的reference,试试看加上using system.web.httpserverutility
          • 没有用的,这个Class本身没有继承System.Web,using 里面怎么加都没有用的。
            • sorry, 我也是刚看见她在class里面用。所以写了下面的。
          • 多说一句,你是在class里面用server的,所以要前面加reference.如果是在web form里面用,就可以直接用了。
            • 多谢!