2016-09-18 32 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

標準表達式中只有一個字段Id。我懷疑,而不是文本它實際上是一個整數。所以刪除引號:(也加入了單引號和where之間的空格)。

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

然而,這讓你打開SQL注入攻擊,所以你應該參數化查詢。

相關問題