问题描述
你好..我还是新手..但我需要帮助..我想将旧的用户名和密码更改为新的...
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);
}
推荐答案
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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!