2016-07-23 17 views
0
protected void Button6_Click(object sender, EventArgs e) 
{ 
    Random rnd = new Random(); 
    string resetpassword = rnd.Next(5000, 100000).ToString(); 
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HealthDBContext"].ConnectionString); 
    conn.Open(); 
    string reset = "UPDATE Users SET" + " [email protected]" + " WHERE [email protected]"; 
    SqlCommand com = new SqlCommand(reset, conn); 
    com.Parameters.AddWithValue("@pass", resetpassword); 
    com.Parameters.AddWithValue("@user", TextBox1.Text); 
    conn.Close(); 
} 

何らかの理由でパスワードが更新されません。更新ステートメントが機能しない

+1

を実行Oooohの、あなたが実際のアプリケーションにプレーンテキストでパスワードを保存していない私に教えてください。 –

+0

このメソッドを 'ExecuteNonQuery();'、あなたが '挿入'、 '削除'、 '更新中'である場合に限り使用します。など –

答えて

1

クエリを実行するのを忘れ:

int cnt = com.ExecuteNonQuery(); 

方法が変更された行の数を返します。

+0

ああ!ありがとう!常にその行を忘れる:( –

1

は、クエリ

protected void Button6_Click(object sender, EventArgs e) 
{ 
    Random rnd = new Random(); 
    string resetpassword = rnd.Next(5000, 100000).ToString(); 
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HealthDBContext"].ConnectionString); 
    conn.Open(); 
    string reset = "UPDATE Users SET" + " [email protected]" + " WHERE [email protected]"; 
    SqlCommand com = new SqlCommand(reset, conn); 
    com.Parameters.AddWithValue("@pass", resetpassword); 
    com.Parameters.AddWithValue("@user", TextBox1.Text); 
    com.ExecuteNonQuery(); 
    conn.Close(); 
} 
関連する問題