0

私はこれを何時間も理解しようとしてきました.ここにいくつかの小さなエラーがあることは知っていますが、それを特定することはできません. 私を助けてください。そこで、「clsDataLayer.cs」というクラスを作成しました。これは App_Code asp.net フォルダーにあります。次に、「frmUserActivity」というフォームを作成しましたが、コードを投稿してクラスを呼び出すと、「「clsDataLayer」は現在のコンテキストに存在しません」と表示されます。

clsDataLayer のコード:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
// Add your comments here
using System.Data.OleDb;
using System.Net;
using System.Data;

namespace ASP_PayRoll.App_Code
{
    public class clsDataLayer
    {
        // This function gets the user activity from the tblUserActivity
        public static dsUserActivity GetUserActivity(string Database)
        {
            // Add your comments here
            dsUserActivity DS;
            OleDbConnection sqlConn;
            OleDbDataAdapter sqlDA;

            // Add your comments here
            sqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + Database);

            // Add your comments here
            sqlDA = new OleDbDataAdapter("select * from tblUserActivity", sqlConn);

            // Add your comments here
            DS = new dsUserActivity();

            // Add your comments here
            sqlDA.Fill(DS.tblUserActivity);

            // Add your comments here
            return DS;
        }

        // This function saves the user activity
        public static void SaveUserActivity(string Database, string FormAccessed)
        {
            // Add your comments here
            OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + Database);
            conn.Open();
            OleDbCommand command = conn.CreateCommand();
            string strSQL;

            strSQL = "Insert into tblUserActivity (UserIP, FormAccessed) values ('" +
                GetIP4Address() + "', '" + FormAccessed + "')";

            command.CommandType = CommandType.Text;
            command.CommandText = strSQL;
            command.ExecuteNonQuery();
            conn.Close();
        }

        // This function gets the IP Address
        public static string GetIP4Address()
        {
            string IP4Address = string.Empty;

            foreach (IPAddress IPA in
                        Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress))
            {
                if (IPA.AddressFamily.ToString() == "InterNetwork")
                {
                    IP4Address = IPA.ToString();
                    break;
                }
            }

            if (IP4Address != string.Empty)
            {
                return IP4Address;
            }

            foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (IPA.AddressFamily.ToString() == "InterNetwork")
                {
                    IP4Address = IPA.ToString();
                    break;
                }
            }

            return IP4Address;
        }
    }
}

frmUserActivity.aspx.cs のコード

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASP_PayRoll
{
    public partial class frmUserActivity : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Declare the DataSet
                dsUserActivity myDataSet = new dsUserActivity();

                //Fill the dataset with what is returned from the function
                myDataSet = clsDataLayer.GetUserActivity(Server.MapPath("PayrollSystem_DB.mdb"));

                //Sets the DataGrip to the DataSource based on the table
                grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"];

                //Binds the DataGrid
                grdUserActivity.DataBind();
            }
        }
    }
}

前もって感謝します。アク

4

2 に答える 2

3

を使用しASP_PayRoll.App_Code.clsDataLayerます。データ層クラスの名前空間は でASP_PayRoll.App_Codeあり、ページではASP_PayRollです。

于 2013-06-06T19:48:21.400 に答える