Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
>
            try
            {
                SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString"].ConnectionString);
              
                        conn1.Open();
                            SqlCommand com1;
                            string insertQuery = "update Personal set PersonalEmail = @email,FirstName = @fname, Surname = @sname,TelephoneNo = @telno, Password = @password Where UserName = '" + LblUserName .Text+ "'";
                            com1 = new SqlCommand(insertQuery, conn1);
                            if (TextBoxNewEmail.Text.Trim() != null)
                            {
                                com1.Parameters.AddWithValue("@email", TextBoxNewEmail.Text);
                            }
                            else
                            {
                                com1.Parameters.AddWithValue("@email", LblOldEmail.Text);
//LblOldEmail holds the value of the users old email 
// TextBoxNewEmail is the textbox where the user enters there new email if they are updating it 

                            }
                
                
                            com1.Parameters.AddWithValue("@password", TextBoxNewPassword.Text);
                            com1.Parameters.AddWithValue("@fname", TextBoxFirstName.Text);
                            com1.Parameters.AddWithValue("@sname", TextBoxSurName.Text);
                            com1.Parameters.AddWithValue("@telno", TextBoxTelNo.Text);
                            // com1.Parameters.AddWithValue("@location", locID);
                            com1.Parameters.AddWithValue("@conText", RadioButtonListText.SelectedValue);
                            com1.Parameters.AddWithValue("@conEmail", RadioButtonListEmail.SelectedValue);


                            com1.ExecuteNonQuery();
                            conn1.Close();
							
							

                        Response.Write("Update was successful");
                    }
                
            
            catch (Exception ex)
            {
                Response.Write("error" + ex.ToString());
            }
Posted
Comments
Ajith K Gatty 23-Apr-14 6:35am    
Little confusing. Can you explain with more details.?
lala24 23-Apr-14 6:41am    
I want to allow the user to update there email if it has changed. when the user logs in they are redirected to their user page. On the user page a label is filled from the database containing there current email. underneath this there are two text boxes new email address and confirm email address. if the user enters a new email address i want to store it in the database otherwise i want to keep the old email address. Hope this clears up my query for you.

1 solution

Hello.

Firstly I think you should change the where clause, because you'll have a sql injection.

Secondly it seems to me that you should compare the new e-mail with the old and if they are different then use the value of the new e-mail, otherwise the old.

JAFC
 
Share this answer
 
Comments
lala24 23-Apr-14 7:17am    
If I use an if else statement like the one above the else is not working and an empty value isreturned to my database
José Amílcar Casimiro 23-Apr-14 8:41am    
You should use the condition like this:
if (TextBoxNewEmail.Text.Trim().Length > 0) { //new email } else { // old email }
lala24 23-Apr-14 9:05am    
could you explain what the >0 means please? thanks
José Amílcar Casimiro 23-Apr-14 9:10am    
If length is bigger than zero.
lala24 23-Apr-14 9:37am    
Thanks a million. Have it working now

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

  Print Answers RSS


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