我运行的代码没有任何错误,但数据库没有更新其字段。
运行时没有错误,但数据库不更新其字段
Sub UpdatePassword(ci As ClientInformation)
Try
Using con As New SqlCeConnection(GetConString)
If con.State = Data.ConnectionState.Closed Then con.Open()
Dim adapt As New SqlCeDataAdapter(String.Format("UPDATE AdminInformation
where ClientID='{0}' SET PWD='{1}'", ci.ClientID, ci.Password), con)
End Using
Catch ex As Exception
End Try
End Sub
我的客户信息类:
Public Class ClientInformation
Public Property ClientID As String
Public Property SubscriptionEndDate As Date
Property FirstName As String
Property Surname As String
Property Email As String
Property Company As String
Property PostalAdd As String
Property Country As String
Property Tel As String
Property Fax As String
Property Password As String
End Class
我的事件处理程序:
Protected Sub btnChangePass_Click(sender As Object, e As EventArgs) Handles
btnChangePass.Click
Dim ci As New ClientInformation
If txtBoxNewPass.Text = txtBoxConfirmNewPass.Text Then
ci.Password = txtBoxNewPass.Text
lblConfirmPasswordMsg.Visible = False
dh.UpdatePassword(ci)
lblPasswordChanged.Visible = True
txtBoxNewPass.Text = ""
txtBoxConfirmNewPass.Text = ""
Else
txtBoxNewPass.Text = ""
txtBoxConfirmNewPass.Text = ""
lblConfirmPasswordMsg.Visible = True
End If
End Sub
我的连接字符串:
Private Function GetConString() As String
Return ConfigurationManager.ConnectionStrings("conStringLicenses").ConnectionString
End Function
任何帮助将不胜感激,提前谢谢。
PS数据库是sql compact,visual studio 2012,windows 7答案 0 :(得分:0)
我认为你的查询应该是这样的
UPDATE AdminInformation SET PWD='{1}' where ClientID='{0}'
您在 SET
之前启动了 WHERE 子句更新:
尝试更改
Dim adapt As New SqlCeDataAdapter(String.Format("UPDATE AdminInformation where ClientID='{0}' SET PWD='{1}'", ci.ClientID, ci.Password), con)
进入这个
Dim cmd As New SqlCeCommand(String.Format("UPDATE AdminInformation SET PWD='{1}' where ClientID='{0}'", ci.ClientID, ci.Password), con)
cmd.ExecuteNonQuery()