2013-08-25 42 views
0

我在寫一個簡單的更新密碼頁(學習目的)。該頁面由兩個文本框控件組成,這些控件允許用戶輸入新密碼,然後通過將其輸入到第二個文本框控件中確認密碼,最後單擊提交底部以更新存儲在其中的表中的密碼一個數據庫。我的問題是,單擊按鈕時出現以下錯誤:初始化字符串的格式不符合從索引0錯誤開始的規範。初始化字符串的格式不符合從索引0開始的規範錯誤

這是代碼在他後面的按鈕:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
     If TextBox2.Text = TextBox3.Text Then 

      Dim myConnectionString As String 
      myConnectionString = "myDbIIConnectionString1" 
      Dim myConnection As New SqlConnection(myConnectionString) 
      myConnection.Open() 

      Dim mySQLQuery As String 
      mySQLQuery = "UPDATE myTb SET password VALUES (@password)" 

      Dim myCommand As New SqlCommand(mySQLQuery, myConnection) 
      myCommand.Parameters.AddWithValue("@password", TextBox3.Text) 
      myCommand.Connection = myConnection 
      myCommand.ExecuteNonQuery() 

      myCommand = Nothing 
      myConnection.Close() 
      myConnection = Nothing 

      Label2.Text = "Your Password has been changed" 
     Else 
      Label2.Text = "Retype your Password" 
     End If 

     Response.Redirect("login.aspx") 
    End Sub 

有人能幫助我一下,我缺少的是什麼嗎?謝謝

回答

0

更新查詢存在問題。將其修正爲:

mySQLQuery = "UPDATE myTb SET [email protected]" 
+0

謝謝,但我仍然得到同樣的錯誤;如果您有任何其他建議,請告訴我。 –

0

我想通了;我應該一直在使用configurationmanager.connectionstrings [「名字在這裏」]。訪問我的連接字符串。

相關問題