{"id":6103,"date":"2017-09-08T07:55:24","date_gmt":"2017-09-07T22:55:24","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6103"},"modified":"2017-09-08T07:55:24","modified_gmt":"2017-09-07T22:55:24","slug":"adoaddnew","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/adoaddnew\/","title":{"rendered":"\u30ec\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\uff08ADO\uff09AddNew \u30e1\u30bd\u30c3\u30c9,Update \u30e1\u30bd\u30c3\u30c9"},"content":{"rendered":"<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b<\/h2>\n<div class=\"m30-l\">\n<h3>AddNew \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u65b0\u898f\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3001\u8ffd\u52a0\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u306b\u30ab\u30fc\u30bd\u30eb\u3092\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>AddNew<\/strong> [ <em>FieldList<\/em>, <em>Values<\/em> ]<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>FieldList&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u8ffd\u52a0\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u8907\u6570\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3092\u6307\u5b9a\u3059\u308b\u306b\u306f\u3001\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3001\u307e\u305f\u306f\u4f4d\u7f6e\u3092\u8868\u3059\u5024\u306e\u4e26\u3073\u3092\u914d\u5217\u3068\u3057\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u53ef\u3002<\/li>\n<li>Values&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u8ffd\u52a0\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u8907\u6570\u306e\u5024\u3092\u6307\u5b9a\u3059\u308b\u306b\u306f\u914d\u5217\u306b\u3057\u307e\u3059\u3002\u7701\u7565\u53ef\u3002<\/li>\n<\/ul><\/div>\n<p class=\"caution4\">\u65b0\u898f\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u3001<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e Open \u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570 <strong>LockType<\/strong> \u306b\u306f\u3001<strong>adLockOptimistic<\/strong> \u307e\u305f\u306f <strong>adLockPessimistic<\/strong> \u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\uff08<strong>Recordset<\/strong> \u3092\u958b\u304f\u6642\u306b\u4f7f\u3046\u30ed\u30c3\u30af\u306e\u7a2e\u985e\u306b\u95a2\u3057\u3066\u306f\u3001<a href=\"https:\/\/excelwork.info\/excel\/databaseadobase\/\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Access \u7b49\uff09\u306b\u63a5\u7d9a\uff08ADO\uff09<\/a> \u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002\uff09<\/p>\n<p class=\"caution4\"><strong>AddNew \u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u547c\u3073\u51fa\u3057\u305f\u5f8c\u306f\u65b0\u898f\u30ec\u30b3\u30fc\u30c9\u304c\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306b\u306a\u308a\u3001<strong>Update \u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u547c\u3073\u51fa\u3057\u305f\u5f8c\u3082\u305d\u306e\u307e\u307e\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p class=\"caution4\">\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u5f8c\u3001\u305d\u306e\u5909\u66f4\u3092\u4fdd\u5b58\u3059\u308b\u306b\u306f\u3001<strong>Update \u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\n    \u305f\u3060\u3057\u3001<strong>Update \u30e1\u30bd\u30c3\u30c9<\/strong>\u5b9f\u884c\u524d\u306b\u3001\u8ffd\u52a0\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u304b\u3089\u79fb\u52d5\u3059\u308b\u3068\u81ea\u52d5\u7684\u306b\u3001<strong>Update \u30e1\u30bd\u30c3\u30c9<\/strong>\u304c\u5b9f\u884c\u3055\u308c\u5909\u66f4\u304c\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n<p class=\"caution4\">\u5f15\u6570\u3092\u7701\u7565\u3057\u3001<strong>Field \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e<strong>Value \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u3092\u4f7f\u7528\u3057\u3066\u30ec\u30b3\u30fc\u30c9\u306e\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u307e\u3059\u3002<\/p>\n<div class=\"m30-l\">\uff08\u4f8b\uff09\u203b rs \u306f\u3001Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/p>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Fields \u30b3\u30ec\u30af\u30b7\u30e7\u30f3\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\n      with rs\r\n          .AddNew\r\n          .Fields(\"ID\").Value = 3\r\n          .Fields(\"NAME\").Value = \"jack\"\r\n          .Fields(\"CONTRY\").Value = \"\u30a2\u30e1\u30ea\u30ab\"\r\n          .Update\r\n      end with\r\n\u3000 \r\n      <\/pre>\n<\/p><\/div>\n<\/p>\n<br \/>\n<h3>Update \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u30ec\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\u3084\u5909\u66f4\u5185\u5bb9\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>Update<\/strong><\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<p class=\"caution4\"><strong>Update \u30e1\u30bd\u30c3\u30c9<\/strong>\u5b9f\u884c\u524d\u5f8c\u3067\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306f\u79fb\u52d5\u3057\u307e\u305b\u3093\u3002<\/p>\n<\/div>\n<br \/><br \/>\n<h2>AddNew \u30e1\u30bd\u30c3\u30c9\u30fbUpdate \u30e1\u30bd\u30c3\u30c9 \u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"AddNew \u30e1\u30bd\u30c3\u30c9\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_AddNew()\r\n\r\n    '\u53c2\u7167\u8a2d\u5b9a:Microsoft ActiveX Data Objects 6.1 Library\r\n\r\n    Dim cn As ADODB.Connection\r\n    Dim rs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFile As String\r\n    Dim strSQL As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n              \r\n    DBFile = ActiveWorkbook.Path & \"\\mydb1.accdb\"\r\n    constr = \"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\" & DBFile\r\n    \r\n    Set cn = New ADODB.Connection\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set rs = New ADODB.Recordset\r\n    With rs\r\n        \r\n        '\u30c6\u30fc\u30d6\u30eb\u3092\u958b\u304f\r\n        .Source = \"\u30c6\u30fc\u30d6\u30eb1\"\r\n        .ActiveConnection = cn\r\n        .CursorType = adOpenKeyset      '\u30ad\u30fc\u30bb\u30c3\u30c8\u30ab\u30fc\u30bd\u30eb\u4f7f\u7528\r\n        .LockType = adLockPessimistic   '\u30ec\u30b3\u30fc\u30c9\u5358\u4f4d\u6392\u4ed6\u7684\u30ed\u30c3\u30af\r\n        .Open\r\n        \r\n        '\u30ec\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\r\n        .AddNew Array(\"ID\", \"NAME\", \"CONTRY\"), Array(3, \"jack\", \"\u30a2\u30e1\u30ea\u30ab\")\r\n        \r\n        '\u5909\u66f4\u5185\u5bb9\u3092\u4fdd\u5b58\r\n        .Update\r\n        \r\n    End With\r\n    \r\n    With Worksheets(\"Sheet1\")\r\n        rs.MoveFirst\r\n        i = 1\r\n        .Cells.Clear\r\n        Do Until rs.EOF\r\n            For j = 0 To rs.Fields.Count - 1\r\n                If i = 1 Then .Cells(i, j + 1) = rs(j).Name\r\n                .Cells(i + 1, j + 1) = rs(j).Value\r\n            Next j\r\n            rs.MoveNext\r\n            i = i + 1\r\n        Loop\r\n    End With\r\n    \r\n    rs.Close\r\n    Set rs = Nothing\r\n    \r\n    cn.Close\r\n    Set cn = Nothing\r\n    \r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adoaddnew_01.jpg?ssl=1\" rel=\"lightbox[6103]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adoaddnew_01.jpg?resize=377%2C246&#038;ssl=1\" alt=\"AddNew \u30e1\u30bd\u30c3\u30c9\uff08ADO\uff09\" width=\"377\" height=\"246\" class=\"alignnone size-full wp-image-6112\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b AddNew \u30e1\u30bd\u30c3\u30c9 \u65b0\u898f\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3001 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6112,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[953,982,950,721,968,974,970,951,983,302,814,955,949,835],"jetpack_featured_media_url":"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adoaddnew_01.jpg?fit=377%2C246&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1Ar","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6103"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=6103"}],"version-history":[{"count":12,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6103\/revisions"}],"predecessor-version":[{"id":6284,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6103\/revisions\/6284"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6112"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}