2016-09-18 4 views
-2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

    Dim con As New OleDb.OleDbConnection 
    Dim str As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=..\VisitorPass.accdb" 
    Dim sql As String 
    sql = "Update Visitor set [password]='" & txtPassword.Text & "',FirstName='" & txtFirstName.Text & "',LastName='" & txtLastName.Text & "',Gender='" & txtGender.Text & "',MobileNo='" & txtMobileNO.Text & "',DateOfBirth='" & txtDateOfBirth.Text & "',VisitorAddress='" & txtVisitorAddress.Text & "'where ID='" & lblID2.Text & "'" 
    con = New OleDbConnection(str) 
    Dim cmd As New OleDbCommand(sql, con) 
    con.Open() 
    cmd.ExecuteNonQuery() 
    Dim obj1 As New VisitorProfile 
    obj1.StringPass = txtName.Text 
    MsgBox("profile is updated") 
    obj1.Show() 
    con.Close() 
    Me.Close() 

End Sub 
+0

助けを求める前に、 'str'の値と更新する列のタイプを質問に追加してください。 – FDavidov

答えて

0

条件式にはフィールドが1つしかありません。Id私はテキストではなく、実際には整数だと思うだろう。したがって、引用符を削除してください:(は、一重引用符とスペースの間にスペースを入れてください)。

"' where ID=" & lblID2.Text & " 

あなたのクエリをパラメータ化する必要がありますのでしかし、これは、SQLインジェクション攻撃に開いてあなたを残します。

関連する問題