需要帮助更改旧的用户名和密码.. c# [英] need help in changing the old username and password.. c#

查看:69
本文介绍了需要帮助更改旧的用户名和密码.. c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好..我还是新手..但我需要帮助..我想将旧的用户名和密码更改为新的...



i am使用mysql数据库..



i想在textbox1和textbox2中输入我的旧用户名和密码..



更新文本框3和文本框4中的用户名和密码..



只有一个按钮是更新按钮..



i尝试了但是当我点击更新按钮时一切都改变了..我只想更新特定的旧用户名和密码..



tq in提前



这是我的编码,...我知道根据我的编码,它将更改所有用户名和密码..但我不知道..我真的需要帮助.. tq



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

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);
            }

推荐答案

首先,

在您的代码中,有一条插入数据的注释,但代码是用于更新记录。所以要照顾好。它不会影响您的代码,但在为特定代码编写注释时仍然有一些很好的做法。 :)



其次,

如果你想更新特定数据,你必须有 where 子句。

字符串Query =update login.database set username ='+ this.textBox3.Text +',password ='+ this.textBox4.Text +'WHERE username ='user@user.com'; //将数据更新到数据库



-KR
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


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


这篇关于需要帮助更改旧的用户名和密码.. c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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