2013-04-17 30 views
0

我正在設計方法 - 在asp.net的改變密碼屏幕,C#,MS-訪問數據庫 IM具有4個字段 用戶ID, 舊密碼, 新密碼 確認密碼改變密碼在asp.net,C#,MS-訪問數據庫

現在即時通訊沒有得到結果count返回0我已經更新了我的代碼

我的代碼如下

 try 

     { 

     OleDbConnection myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["vhgroupconnection"] 
     .ConnectionString); 
     myCon.Open(); 

     string userid = txtuserid.Text; 
     string oldpass = txtoldpass.Text; 
     string newPass = txtnewpass.Text; 
     string conPass = txtconfirmpass.Text; 

     string q = "select user_id,passwd from register where user_id = @userid and  passwd = @oldpass"; 

     OleDbCommand cmd = new OleDbCommand(q, myCon); 



     cmd.Parameters.AddWithValue("@userid", txtuserid.Text); 

     cmd.Parameters.AddWithValue("@oldpass", txtoldpass.Text); 

     OleDbDataReader re = cmd.ExecuteReader(); 
     re.Read(); 

     if (re["user_id"].ToString() != String.Empty && re["passwd"].ToString() != String.Empty) 
     { 
      if (newPass.Trim() != conPass.Trim()) 
      { 
       lblmsg.Text = "New Password and old password does not match"; 

      } 
      else 
      { 
       q = "UPDATE register SET passwd = @newPass WHERE user_id [email protected]"; 
       cmd = new OleDbCommand(q, myCon); 
       cmd.Parameters.AddWithValue("@userid", txtuserid.Text); 
       cmd.Parameters.AddWithValue("@newPasss", txtnewpass.Text); 



       int count = cmd.ExecuteNonQuery(); 

       if (count > 0) 
       { 
        lblmsg.Text = "Password changed successfully"; 
       } 
       else 
       { 
        lblmsg.Text = "password not changed"; 
       } 
      } 
     } 
    } 
    catch(Exception ex) 
    { 
     throw ex; 
    } 

plz幫助我解決錯誤

回答

2

您會收到錯誤No constructor is defined,因爲您無法直接實例化此對象。作爲MSDN說:

要創建OleDbDataReader,必須調用OleDbCommand對象的ExecuteReader方法 ,而不是直接使用構造函數。

從本質上講,你會創建連接並指定查詢後,執行類似如下:

OleDbDataReader re = cmd.ExecuteReader(); 
+0

我嘗試了,但是當我調試的代碼,它表現出異常,因爲前{「沒有給定值「} System.Exception {System.Data.OleDb.OleDbException} – dev

+0

我得到的答案我改變我的更新查詢爲:q =」更新寄存器SET密碼='「+ txtnewpass.Text +」'在哪裏user_id ='「+ txtuserid.Text +」'「;它成功地工作,感謝您的幫助 – dev