Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here anyone tell me please how to show profile info in lable...when user click on update and info in label
sp is
C#
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
C#
public void updateuser(string FullName, string Email, string phonenumber)
        {
            db.ExecuteNonQuery("spupdateuser", new object[] { FullName, Email, phonenumber });


        }


and button code is

C#
protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {
                cg.updateuser(TextBox1.Text, TextBox2.Text, TextBox3.Text);
            }
            catch
            {
                Label14.Text = ("Update Succesfully");
            }
        }
Posted
Comments
Karthik Harve 10-Apr-13 5:01am    
your label is showing "Updated Successfully". so, what text you want to show in the label ? profile info means what in your context ?
Nandakishore G N 10-Apr-13 5:08am    
dont perform it in codebehind..use stored procedure output parameter.and read it after execution..
ariesareej 10-Apr-13 5:18am    
KARTHIK i show full name ,email ,phone number in labels
ariesareej 10-Apr-13 5:18am    
nandakishorerao how?

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

C#
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");
    }
}


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

This will hopefully make things clearer for you
 
Share this answer
 
v2
Comments
ariesareej 10-Apr-13 6:34am    
now i have 2 buttons one is edit and other is update ..when i click edit button it shows me texboxes then when i enter values in textboxes and cilick on update button then it will be save and show me in label....this is where i want to be done..???
Add the values of the textbox to the label
C#
cg.updateuser(TextBox1.Text, TextBox2.Text, TextBox3.Text);
Label14.Text = TextBox1.Text + " "+ TextBox2.Text + " " + TextBox3.Text;
 
Share this answer
 
Comments
ariesareej 11-Apr-13 2:59am    
when i click on edit button it show me textboxes then when i enter values in textboxes and click on update button then it not show be update values in 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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900