我正在写一个简单的更新密码页面(学习目的)。该页面包含两个文本框控件,允许用户输入新密码,然后通过将密码输入第二个文本框控件确认密码,最后单击提交底部以更新存储在表中的密码一个数据库。我的问题是按钮单击时收到以下错误:初始化字符串的格式不符合从索引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 :(得分:0)
您的更新查询存在问题。把它纠正为:
mySQLQuery = "UPDATE myTb SET password=@password"
答案 1 :(得分:0)
我明白了;我应该一直在使用configurationmanager.connectionstrings [“这个名字在这里”]。访问我的连接字符串。