本文介绍了如何添加名称空间数据管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 'usermanager' 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/
推荐答案
这篇关于如何添加名称空间数据管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!