更新个人资料并在标签中显示个人资 [英] update profile and show profile in label

查看:45
本文介绍了更新个人资料并在标签中显示个人资的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有人告诉我如何在标签中显示个人资料信息...当用户点击标签上的更新和信息时

sp是

here anyone tell me please how to show profile info in lable...when user click on update and info in label
sp is

ALTER procedure [dbo].[spupdateuser]
@UserID int,
@FullName nvarchar(50),
@Email nvarchar(50),
@PhoneNumber nvarchar(50)
as
update  [Users] set FullName=@FullName,Email=@Email,PhoneNumber=@PhoneNumber
where UserID=@UserID





功能是



funtion is

public void updateuser(string FullName, string Email, string phonenumber)
        {
            db.ExecuteNonQuery("spupdateuser", new object[] { FullName, Email, phonenumber });


        }





和按钮代码是





and button code is

protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {
                cg.updateuser(TextBox1.Text, TextBox2.Text, TextBox3.Text);
            }
            catch
            {
                Label14.Text = ("Update Succesfully");
            }
        }

推荐答案

你无法成功更新捕获内部的消息。 catch语句保留用于异常,您可以在异常处理期间使用它。您可以添加finally语句,但无论您的代码是否成功,都会执行。



如果您的其他代码是,我可以推荐以下最佳选项工作



You can''t have an "Updated Successfully" message inside of a catch. A catch statement is reserved for exceptions and you would make use of it during exception handling. You could add the finally statement but then that would always execute whether you code was successful or not.

Best option I can recommend is the following, provided your other code is working

protected void Button1_Click1(object sender, EventArgs e)
{
    try
    {
        cg.updateuser(TextBox1.Text, TextBox2.Text, TextBox3.Text);
        Label14.Text = ("Update Succesfully");
    }
    catch
    {
        Label14.Text = ("Update Failed");
    }
}





请通读microsoft文档。

http://msdn.microsoft.com/en-us/library/vstudio/0yd65esw.aspx [ ^ ]



这有望让你更清楚



please read through microsoft documentation.
http://msdn.microsoft.com/en-us/library/vstudio/0yd65esw.aspx[^]

This will hopefully make things clearer for you


将文本框的值添加到标签

Add the values of the textbox to the label
cg.updateuser(TextBox1.Text, TextBox2.Text, TextBox3.Text);
Label14.Text = TextBox1.Text + " "+ TextBox2.Text + " " + TextBox3.Text;


ariesareej,我想你想更新数据库中用户的详细信息,并希望在标签上显示更新的值。 Anuja上面的解决方案就是你想要的。我想补充一点的是你应该更优雅地处理这些条件。我相信上面的解决方案只是一个指导方针。在真实场景中,假设您触发更新查询,并且表格未因某种原因而更新。您的标签仍会显示更新的值!因此,为了实现您想要的,请使用ExecuteReader()而不是ExecuteNonQuery()。在您的查询中处理条件并返回结果。 已更新,失败或更新的行的值。在您的代码中,检查来自查询的响应,并相应地在Label上显示消息。我希望这对你有帮助。
ariesareej, I think you want to update the details of the user in the database and want to show the updated values back on the label. The solution above by Anuja is just what you want. One thing I would like to add is that you should handle these sorts of conditions more gracefully. I am sure that the solution above is given to you as just a guiding line. In real world scenario, suppose you fire the update query, and the table is not updated for a reason. Still your label will show the updated values! So, in order to achieve what you want, use ExecuteReader() instead of ExecuteNonQuery(). In your query handle the conditions and return the result. "Updated", "Failed" or the values of the updated Row. In your code behind check the response from query and accordingly display the message on the Label. I hope this may help you.


这篇关于更新个人资料并在标签中显示个人资的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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