Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello.. i am still a newbie.. but i need help.. i want to change old username and password to a new one..

i am using mysql database..

i want to enter my old username and password in textbox1 and textbox2..

the update username and password in textbox3 and textbox4..

and only one button which is update button..

i did try it but everything changed when i clicked the update button.. i only wanted the specific old username and password to be update..

tq in advance

this is my coding,.. i know based on my coding it will changed all username and password.. but i did not have any idea.. i really need help.. tq

C#
private void button1_Click(object sender, EventArgs e)
        {
            string constring = "datasource=localhost; port=3306;username=root;password=";
         
            string Query = "update login.database set  username='" + this.textBox3.Text + "', password= '" + this.textBox4.Text + "';"; // to insert data to database
            MySqlConnection conDataBase = new MySqlConnection(constring);
            MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
            MySqlDataReader myReader;

            try
            {
                conDataBase.Open();
                myReader = cmdDataBase.ExecuteReader();
                MessageBox.Show("Update");
                while (myReader.Read())
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
Posted
Updated 16-Mar-14 20:32pm
v2

First,
In your code, there's a comment for inserting the data, but the code is for updating record. So take care of that. It won't affect your code, but still have some good practice in writing comments for particular piece of code. :)

Second,
if you want to update particular data, you must have where clause in your query.
string Query = "update login.database set username='" + this.textBox3.Text + "', password= '" + this.textBox4.Text + "' WHERE username='user@user.com'"; // to update the data into database

-KR
 
Share this answer
 
You just missed the condition only as per krunal Rohit the query needs a condition for update data otherwise it will affect all rows of table.

For this You design should required 
Old User Name:_______________
Old Password:________________
New username:________________
New Password:________________

It needs more condition only like
 ".......
 WHERE username='"+txtOldUserName.Text+"' and password='"+txtOldPassword.Text+"'"; 

See the concept for what to do
 
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