使用n-tire asp.net获取和检索数据
本文关键字:检索 数据 获取 net n-tire asp 使用 | 更新日期: 2023-09-27 18:26:00
使用n-tire asp.net获取和检索数据
大家好,我已经制作了n个轮胎来插入、更新、选择和删除
插入和删除工作正常,但我有问题,使选择所有数据,以便进行更新
这是db.class中可以执行连接的方法
public void ConnectDB(CommandType CT,string ProNameSQl)
{
cn = new SqlConnection("Data Source=.;Initial Catalog=Conversation;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CT;
cmd.CommandText = ProNameSQl;
cn.Open();
}
public int RunProcedure(string ProcedureName, SortedList Paraval)
{
ConnectDB(CommandType.StoredProcedure, ProcedureName);
for (int x = 0; x < Paraval.Count; x++)
{
try
{
cmd.Parameters.AddWithValue(Paraval.GetKey(x).ToString(), Paraval.GetByIndex(x));
}
catch
{
;
}
}
return ExceNoneQuery();
}
public DataTable RunSQl(string Select)
{
ConnectDB(CommandType.Text, Select);
dt=new DataTable();
dt.Load(cmd.ExecuteReader());
cn.Close();
return dt;
}
然后在检查后,我制作另一个类来传递操作类型"i"指的是sql中的过程名称
public bool Add()
{
return LoadProperties2List("i");
}
如果一切正常,它会运行到最后一个轮胎,在那里代码可以像插入一样执行
public class UsersInfo :MainTable
{
#region Feild
private string _id;
private string _username;
private string _SecondarySchool;
private string _University;
#endregion
#region Properties
public string id
{
get
{
return _id;
}
set
{
_id = value;
}
}
public string UserName
{
get
{
return _username;
}
set
{
_username = value;
}
}
public string SecondarySchool
{
get
{
return _SecondarySchool;
}
set
{
_SecondarySchool = value;
}
}
public string University
{
get
{
return _University;
}
set
{
_University = value;
}
}
#endregion
public override bool LoadProperties2List(string TypeOfOperation)
{
SortedList Sl = new SortedList();
Sl.Add("@CommandType", TypeOfOperation);
Sl.Add("@UserName",UserName);
Sl.Add("@SecondarySchool",SecondarySchool);
Sl.Add("@University",University);
ProcedureName = "MangeUserInfo";
if (db.RunProcedure(ProcedureName, Sl) == 1)
return true;
else
return false;
}
public bool Register(string User, string SecondaryS, string Unvi)
{
this.UserName = User;
this.SecondarySchool = SecondaryS;
this.University = Unvi;
if (Add())
return true;
else
return false;
}
这段代码运行良好。如何使用这些层来检测和检索数据库,并在文本框中显示它们???使用相同的层
感谢我为解决问题所做的一切我确实喜欢这个的例子
public bool find(string usernameid)
{
string query = String.Format("SELECT id FROM Users WHERE UserName='{0}'", usernameid);
DataTable tbl = SeectData(query);
if (tbl.Rows.Count == 0)
return false;
else
{
this.id = tbl.Rows[0][0].ToString();
return true;
}
}
然后在页面加载中调用它
if (SelD.find(username))
{
UserNid = SelD.id;
}
它工作得很好谢谢所有