{"id":58,"date":"2009-06-10T03:47:21","date_gmt":"2009-06-10T01:47:21","guid":{"rendered":"http:\/\/dirk.forbiddendream.be\/?p=58"},"modified":"2016-01-07T10:50:19","modified_gmt":"2016-01-07T10:50:19","slug":"working-with-databases-oledb-ms-access-2007-code-wise-update-insert-delete-commands","status":"publish","type":"post","link":"https:\/\/dirk.schuermans.me\/?p=58","title":{"rendered":"Working with databases (OleDb, MS Access 2007) code-wise (UPDATE, INSERT, DELETE COMMANDS)"},"content":{"rendered":"<p>In my previous post <a href=\"http:\/\/dirk.schuermans.me\/?p=46\">Working with databases (OleDb, MS Access 2007) code-wise (SELECT COMMAND)<\/a> I&#8217;ve made a small introduction regarding this matter, so I won&#8217;t bother doing the same here.<\/p>\n<p>In order to execute UPDATE, INSERT OR DELETE statements against our database, we pretty much need the same objects as we did for retrieving data from a database:<\/p>\n<ol>\n<li>A database connection\n<li>A SQL command\n<\/ol>\n<p>We&#8217;ll start off again by declaring the objects we need:<\/p>\n<p><!--more--><\/p>\n<pre name=\"code\" class=\"vb.net\">'Declaring required objects\r\nDim oCon As New OleDb.OleDbConnection(\"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=MyDatabase.accdb;Persist Security Info=False;\")\r\nDim oCommand As New OleDb.OleDbCommand(\"\", con)<\/pre>\n<p><\/p>\n<p>The following code snippet will show how to execute one of the statements:<\/p>\n<pre name=\"code\" class=\"vb.net\">'Code example for executing an UPDATE statement against our database\r\nTry\r\n\t'Set the query\r\n\toCommand.CommandText = \"UPDATE MyTable SET MyField = 'MyNewValue' WHERE MyField = 'MyCurrentValue'\"\r\n\r\n\t'Open connection\r\n\toCon.Open()\r\n\r\n\t'Execute the command\r\n\toCommand.ExecuteNonQuery()\r\n\r\n\t'Close connection\r\n\toCon.Close()\r\n\r\nCatch ex As OleDb.OleDbException\r\n\t'Show oledb exception\r\n\tMessageBox.Show(ex.ToString)\r\nEnd Try\r\n<\/pre>\n<p>Now this example showed how to do UPDATE commands, but in order to execute INSERT or DELETE statement it works the exact same way.<br \/>\nJust replace the <b>oCommand.CommandText = &#8220;&#8230;&#8221;<\/b> with the statement you wish to use \ud83d\ude42<\/p>\n<p>Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post Working with databases (OleDb, MS Access 2007) code-wise (SELECT COMMAND) I&#8217;ve made a small introduction regarding this matter, so I won&#8217;t bother doing the same here. In order to execute UPDATE, INSERT OR DELETE statements against our database, we pretty much need the same objects as we did for retrieving data &hellip; <a href=\"https:\/\/dirk.schuermans.me\/?p=58\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Working with databases (OleDb, MS Access 2007) code-wise (UPDATE, INSERT, DELETE COMMANDS)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[38],"tags":[17,18,19,20,22,23,25,27],"_links":{"self":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts\/58"}],"collection":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":2,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}