私はc#でwebmethodをやっています。デバッグ時、
(chk.Equals(oldpass))
クエリは、左側と右側の両方に同じ値を示します。
それでも、ifの中に入るのではなく、return文を示すelse部分に実行が移ります。フォール。私のコードです。
[WebMethod (Description="for change in password")]
public string update(string authenid,string oldpass,string newpass)
{
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Workspace\\visual studio workspace\\Tmrepo\\App_Data\\tmrepo.mdf;Integrated Security=True;User Instance=True");
try
{
conn.Open();
string chk = "select pwd from client where authenid = '"+ @authenid +"' ";
if(chk.Equals(oldpass))
{
string update = "update client set pwd=@newpass where pwd=@oldpass and authenid=@authenid";
SqlCommand cmd = new SqlCommand(update, conn);
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@authenid", authenid);
cmd.Parameters.AddWithValue("@oldpass", oldpass);
cmd.Parameters.AddWithValue("@newpass", newpass);
cmd.ExecuteNonQuery();
}
else
{
return "invalid oldpass";
}
conn.Close();
return newpass;
}
catch (Exception ex)
{
return ex.ToString();
}
}
このコードに何か問題がありますか? 私は ac# 初心者です。ありがとう。