使用 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中的procdure名称
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;
}
此代码工作正常如何使用这些层来销售和检索数据库并在文本框中显示它们???使用相同的图层