here is my update code: (Button Click event)
Dim con As New OleDbConnection
Dim sql As String
'Dim i As Integer
con.ConnectionString = "provider = Microsoft.ACE.OLEDB.12.0; data source = ..\sample.accdb"
sql = "update list set LName = ' " & txtLName.Text & " ' [size="3"][size="5"][b]where ID = (' " & txtID.Text & " '[/b][/size][/size]) ; "
Dim cmd As OleDbCommand
Try
con.Open()
cmd = New OleDbCommand(sql, con)
cmd.ExecuteScalar()
MessageBox.Show("Update Successfully")
con.Close()
cmd.Dispose()
Catch ex As OleDbException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
i think that my problem starts on the where condition, because when i removed it the update query works fine, it's just that it updates ALL LName's in my database.
i forgot. i also try this code:
Dim con As New OleDbConnection
Dim sql As String
[b][size="3"]Dim i As Integer[/size][/b]
con.ConnectionString = "provider = Microsoft.ACE.OLEDB.12.0; data source = ..\sample.accdb"
'con = New OleDbConnection(con.ConnectionString)
sql = "update list set LName = ' " & txtLName.Text & " ' where ID = (' " & dgvSearch.Rows(0).Cells("ID").Value & " ') ; "
Dim cmd As OleDbCommand
Try
con.Open()
cmd = New OleDbCommand(sql, con)
cmd.ExecuteScalar()
MessageBox.Show("Update Successfully")
con.Close()
cmd.Dispose()
Catch ex As OleDbException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
i tried this code to call the first column, which is the ID, in my dgvSearch. yet it still doesn't work
This post has been edited by smohd: 18 July 2012 - 04:55 AM
Reason for edit:: Code tags added. Please use [code] tags when posting codes

New Topic/Question
Reply



MultiQuote



|