Private Sub UpdateRecord()
Dim s As String = "UPDATE tblTable SET Field1 = 'VALUE' WHERE Field2 = 'THISONE'"
Dim c As String = "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\mydb.mdb;Uid=admin;Pwd="
If SQLPerformOne(s,c) = False Then
'...Error
End If
End Sub
'send an single SQL string to be run.
'return: a boolean to see if all the scripts ran ok.
Public Function SQLPerformOne(ByVal sSQL As String, ByVal sConn As String) As Boolean
'--Create and open connection/Command
Dim objConn As SqlConnection = New SqlConnection(sConn)
Dim objCmd As SqlCommand = New SqlCommand(UCase(sSQL), objConn)
objConn.Open()
Try
objCmd.ExecuteNonQuery() '--execute Query
'--close everything
objConn.Close()
objConn = Nothing
Return True
Catch ex As Exception
MsgBox(ex)
objConn.Close()
objConn = Nothing
Return False
End Try
End Function