如何添加名称空间数据管理器 [英] how to add name space datamanager

查看:116
本文介绍了如何添加名称空间数据管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

datamanagerclass :(名称空间)
--------------------------------------------------

datamanagerclass:(name space)
--------------------------------------------------

public datamanager()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public Boolean CreateReader()
    {
        try
        {
            if (cn.State == ConnectionState.Open)
                cn.Close();
            cmd.Connection = cn;
            cn.Open();
            Reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch
        {
            if (cn != null)
                cn.Close();
            return false;
        }
        return true;
    }

    public Boolean GetData()
    {
        return Reader.Read();
    }

    public string updatedata()
    {
        try
        {
            if (cn.State == ConnectionState.Open)
                cn.Close();
            cmd.Connection = cn;
            cn.Open();
            int nRec = cmd.ExecuteNonQuery();
            cn.Close();
            if (nRec == 0)
            { return "Update failed.."; }
        }
        catch (Exception ex)
        {
            if (cn != null)
                cn.Close();
            return "Data Update Error:" + ex;
        }
        return "";
    }

    public DataTable GetTable()
    {
        ds.Tables.Clear();
        try
        {
            if (cn.State == ConnectionState.Open)
                cn.Close();
            cmd.Connection = cn;
            cn.Open();
            da.SelectCommand = cmd;
            da.Fill(ds);
        }
        catch
        {
            if (cn != null)
                cn.Close();
            return null;
---------------------------------------------------------
//registration.aspx:
-----------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Registration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!usermanager.adminexist())
            Response.Redirect("adminregform.aspx");
        if (!IsPostBack)
        {
            Catogorymanager cman = new Catogorymanager();
            DrpCategory.DataSource=cman.GetCategoryList();
            DrpCategory.DataTextField = "category";
            DrpCategory.DataValueField = "catid";
            DrpCategory.DataBind();
        }
    }
    protected void Btnsubmit_Click(object sender, EventArgs e)
    {
        
        if (usermanager.UserExist(Txtuid.Text))
        {
            Response.Write("User already exists!!..");
            return;
        }
        datamanager dm = new datamanager();
        dm.cmd.CommandText = "insert into registrform(userid,firstname,lastname,paswrd,catgid,dob,gadiname,Regdate) values(@uid,@fnam,@lnam,@pwd,@catgryid,@dob,@gname,@rgdt)";
        dm.cmd.Parameters.AddWithValue("uid", Txtuid.Text);
        dm.cmd.Parameters.AddWithValue("fnam", txtfname.Text);
        dm.cmd.Parameters.AddWithValue("lnam", txtlname.Text);
        dm.cmd.Parameters.AddWithValue("pwd", txtpwd.Text);
        dm.cmd.Parameters.AddWithValue("retyp", Txtretype.Text);
        dm.cmd.Parameters.AddWithValue("catgryid",DrpCategory.SelectedValue);
       dm.cmd.Parameters.AddWithValue("dob",DateTimePicker1.DataDate);
        dm.cmd.Parameters.AddWithValue("gname",Txtgadian.Text);
        dm.cmd.Parameters.AddWithValue("rgdt", DateTime.Now);
        string res = dm.updatedata();
        if (res != "")
            Response.Write("Unable to update Data..");
        else
        {
            //Txtuid.Text = "";
        }
    }
}

        }
        return ds.Tables[0];
    }

}

<pre lang="msil">Error   1   The name &#39;usermanager&#39; does not exist in the current context    c:\inetpub\wwwroot\ramyamessage\adminregform.aspx.cs    16</pre>





Error   2   The type or namespace name 'datamanager' could not be found (are you missing a using directive or an assembly reference?)   c:\inetpub\wwwroot\ramyamessage\adminregform.aspx.cs    33


Error   3   The type or namespace name 'Catogorymanager' could not be found (are you missing a using directive or an assembly reference?)   c:\inetpub\wwwroot\ramyamessage\MsgCategoryaspx.aspx.cs 17  9   http://localhost/ramyamessage/


Error   4   The type or namespace name 'Catogorymanager' could not be found (are you missing a using directive or an assembly reference?)   c:\inetpub\wwwroot\ramyamessage\MsgCategoryaspx.aspx.cs 17  35  http://localhost/ramyamessage/

推荐答案

我怀疑核心问题是您不知道自己在做什么. .NET中的任何类都不能存在于名称空间之外.您的数据管理器类需要位于Web应用程序的app_code部分中.您有一个数据管理器"类,但是您正在用aspx编写SQL.您应该购买一本ASP.NET书籍并阅读.
I suspect the core issue is that you have no idea what you''re doing. No classes in .NET can exist outside of a namespace. Your data manager class needs to be in the app_code section of your web app. You have a ''datamanager'' class, yet you''re writing SQL in your aspx. You should buy an ASP.NET book and read it.


这篇关于如何添加名称空间数据管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆