使用n -tire更新数据 [英] update data using n -tire do nothing
问题描述
我有3个轮胎在商业层中执行我的代码我运行代码进行更新
public 覆盖 bool LoadProperties2List( string TypeOfOperation)
{
SortedList Sl = new SortedList();
Sl.Add( @ CommandType,TypeOfOperation);
Sl.Add( @ UserName,UserName);
Sl.Add( @ SecondarySchool,SecondarySchool);
Sl.Add( @ University,University);
Sl.Add( @ Qualification,资格认证);
Sl.Add( @ JobTitle,JobTitle);
Sl.Add( @ Company,Company);
Sl.Add( @ PhotoUrl,PhotoUrl);
ProcedureName = MangeUserInfo;
if (db.RunProcedure(ProcedureName,Sl)== 1 )
返回 true ;
else
return false < /跨度>;
}
public bool updateUser( string 用户,字符串 SecondaryS, string Unvi, string Qua, string jobtitle, string company)
{
this .UserName = User;
此 .SecondarySchool = SecondaryS;
this .University = Unvi;
此 .Qualification = Qua;
此 .JobTitle = jobtitle;
此 .Company = company;
if (Update())
return 真跨度>;
else
return false < /跨度>;
}
和数据访问层
< pre lang =c#> public void ConnectDB(CommandType CT, string ProNameSQl)
{
cn = new SqlConnection( 数据源=。;初始目录=会话;集成安全性=真);
cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CT;
cmd.CommandText = ProNameSQl;
cn.Open();
}
public int RunProcedure(< span class =code-keyword> string ProcedureName,SortedList Paraval)
{
ConnectDB(CommandType.StoredProcedure,ProcedureName);
for ( int x = 0 ; x < Paraval.Count; x ++)
{
尝试
{
cmd.Parameters.AddWithValue(Paraval.GetKey(x).ToString(),Paraval.GetByIndex(x));
}
catch
{
;
}
}
return ExceNoneQuery();
}
然后在另一层我使用此方法调用过程进程类型并运行
public bool Update()
{
return LoadProperties2List( U跨度>);
}
在最后一层presenation图层
i这样做
受保护 void btnsave_Click( object sender,EventArgs e)
{
// upadate info
bool 结果= false ;
UsersInfo Upd = new UsersInfo();
try
{
Result = Upd.updateUser(username,TxtSecondarySchool.Text,TxtUniversity.Text,TxtQualification。 Text,TxtJobTitle.Text,TxtCompany.Text);
if (Result == true )
lblMessage.Text = 记录已成功更新。;
else
lblMessage.Text = 记录无法更新;
}
catch (例外ee)
{
lblMessage .Text = ee.Message.ToString();
} 最后
{
Upd = 空跨度>;
}
}
当我只运行代码时结果是
lblMessage.Text = 记录无法更新;
是什么错误让它无法正常工作?
i发现一些奇怪的东西尽管改变了原因,文本框并没有采用它传递相同值的新值。我需要帮助??
错误是..
文本框加载例程Page Startup事件,在If IsNotPostback循环之外的常规位置...
所以默认值只是在每次刷新页面时重新加载,因此看起来像是'不可改变的'..
试试好运
即使你几乎已经在这里发布了整个源代码,这里的某些人真的很难找到究竟发生了什么。
Visual Studio是你最好的朋友。请相信我,他们拥有的调试器是在这种情况下帮助你的最好的调试器之一。
如果我是你,我会在更新中设置一个断点()函数,看看发生了什么。
顺便说一句,这是MSDN上关于如何使用Visual Studio进行调试的链接。
http://msdn.microsoft.com/en-us/library /vstudio/sc65sadd.aspx [ ^ ]
i have got 3 tire wherecarry out my code in bussiness layer i run code for update
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);
Sl.Add("@Qualification",Qualification);
Sl.Add("@JobTitle",JobTitle);
Sl.Add("@Company",Company);
Sl.Add("@PhotoUrl", PhotoUrl);
ProcedureName = "MangeUserInfo";
if (db.RunProcedure(ProcedureName, Sl) == 1)
return true;
else
return false;
}
public bool updateUser(string User, string SecondaryS, string Unvi, string Qua, string jobtitle, string company)
{
this.UserName = User;
this.SecondarySchool = SecondaryS;
this.University = Unvi;
this.Qualification = Qua;
this.JobTitle = jobtitle;
this.Company = company;
if (Update())
return true;
else
return false;
}
and in data access layer
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();
}
and then in another layer i use this method to call procedure process kind and run
public bool Update()
{
return LoadProperties2List("u");
}
at last layer presenation layer
i do that
protected void btnsave_Click(object sender, EventArgs e)
{
//upadate info
bool Result = false;
UsersInfo Upd = new UsersInfo();
try
{
Result = Upd.updateUser(username, TxtSecondarySchool.Text, TxtUniversity.Text, TxtQualification.Text, TxtJobTitle.Text, TxtCompany.Text);
if (Result==true)
lblMessage.Text = "Record Updated Successfully.";
else
lblMessage.Text = "Record couldn't updated";
}
catch (Exception ee)
{
lblMessage.Text = ee.Message.ToString();
} finally
{
Upd = null;
}
}
when i run the code only the result is
lblMessage.Text = "Record couldn't updated";
what is the error which maks it not to work correctly ??
i alse find something strange that the textboxes doesnt take the new values it pass the same value despite change why ??? i need help ??
the error is ..
the textbox load in a routine in the Page Startup event, with the routine place outside the If IsNotPostback loop...
so the default value just reloaded every time the page is refreshed, and thus appear to be 'unchangeable'..
try it good luck
Even though you virtually have posted the whole source code here, its really difficult for some one here to find out exactly what is happening.
Visual Studio is your best friend. And trust me the debugger they have is one of the best ones to help you in this scenario.
If I were you, I would put a break-point in Update() function and see what is happening.
Btw, here is a link on MSDN on how to debug using Visual Studio.
http://msdn.microsoft.com/en-us/library/vstudio/sc65sadd.aspx[^]
这篇关于使用n -tire更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!