SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=Library;Integrated Security=True;Pooling=False;Asynchronous Processing=true";
string sqlsel = "select password from Admin where password='" + textBox30.Text + "'";
conn.Open();
SqlCommand ccmd = new SqlCommand(sqlsel, conn);
SqlDataReader sdr = ccmd.ExecuteReader();
string strsql = "update Admin set password='" + textBox31.Text + "'where username='bluesky'";
SqlCommand cmd = new SqlCommand(strsql, conn);
if (sdr.Read())
{
MessageBox.Show("密码更新成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("原始密码错误,密码更新失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
为什么提示更新成功,数据库中却没有变呢?
conn.ConnectionString = "Data Source=.;Initial Catalog=Library;Integrated Security=True;Pooling=False;Asynchronous Processing=true";
string sqlsel = "select password from Admin where password='" + textBox30.Text + "'";
conn.Open();
SqlCommand ccmd = new SqlCommand(sqlsel, conn);
SqlDataReader sdr = ccmd.ExecuteReader();
string strsql = "update Admin set password='" + textBox31.Text + "'where username='bluesky'";
SqlCommand cmd = new SqlCommand(strsql, conn);
if (sdr.Read())
{
MessageBox.Show("密码更新成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("原始密码错误,密码更新失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
为什么提示更新成功,数据库中却没有变呢?
if (sdr.Read())
{
MessageBox.Show("密码更新成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("原始密码错误,密码更新失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} 这里出问题了。
sdr.Read()仅仅表示数据库存在指定的记录。
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=Library;Integrated Security=True;Pooling=False;Asynchronous Processing=true";
//string sqlsel = "select password from Admin where password='" + textBox30.Text + "'";
conn.Open();
SqlCommand ccmd = new SqlCommand(sqlsel, conn);
//SqlDataReader sdr = ccmd.ExecuteReader();
string strsql = "update Admin set password='" + textBox31.Text + "'where username='bluesky'";
SqlCommand cmd = new SqlCommand(strsql, conn);
int count=cmd.ExecuteNonQuery();
if (count>0)
{
MessageBox.Show("密码更新成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("原始密码错误,密码更新失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=Library;Integrated Security=True;Pooling=False;Asynchronous Processing=true";
string sqlsel = "select password from Admin where password='" + textBox30.Text + "'";
conn.Open();
SqlCommand ccmd = new SqlCommand(sqlsel, conn);
SqlDataReader sdr = ccmd.ExecuteReader();
if (!sdr.HasRows)
{
MessageBox.Show("原始密码错误,密码更新失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
sdr.Close();
conn.Close();
string strsql = "update Admin set password='" + textBox31.Text + "'where username='bluesky'";
SqlCommand cmd = new SqlCommand(strsql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("密码更新成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);;
}