{"id":6188,"date":"2017-09-18T08:50:22","date_gmt":"2017-09-17T23:50:22","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6188"},"modified":"2017-10-23T12:56:04","modified_gmt":"2017-10-23T03:56:04","slug":"adoexecutesql","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/adoexecutesql\/","title":{"rendered":"SQL\u6587\u3092\u5b9f\u884c\u3059\u308b(ADO)Execute \u30e1\u30bd\u30c3\u30c9"},"content":{"rendered":"<h2>Command \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e Execute \u30e1\u30bd\u30c3\u30c9\u3067\u3001SQL\u6587\u3092\u5b9f\u884c<\/h2>\n<div class=\"m30-l\">\n<p><strong>Command \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u3067 <strong>Execute \u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001<strong>CommandText \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u6307\u5b9a\u3057\u305fSQL\u6587\u3084\u30af\u30a8\u30ea\u7b49\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<strong>CommandText \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u7d50\u679c\u3092\u8fd4\u3059 SQL\u6587\u3084\u30af\u30a8\u30ea\u7b49\u304c\u6307\u5b9a\u3055\u308c\u305f\u5834\u5408\u3001\u65b0\u898f\u306e <strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<br \/>\n    \u30d1\u30e9\u30e1\u30fc\u30bf\u30af\u30a8\u30ea\u306e\u5834\u5408\u306f\u3001\u5f15\u6570\u306e <strong>Parameters<\/strong> \u306b\u30af\u30a8\u30ea\u306b\u6e21\u3059\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u30d1\u30e9\u30e1\u30fc\u30bf\u30af\u30a8\u30ea\u306b\u95a2\u3057\u3066\u306e\u8a73\u7d30\u306f\u3001<a href=\"https:\/\/excelwork.info\/excel\/adocommand\/\">\u30af\u30a8\u30ea\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3057\u3066\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308b\uff08ADO\uff09Command \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30fbExecute \u30e1\u30bd\u30c3\u30c9<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3 id=\"command_execute\">Command.Execute \u30e1\u30bd\u30c3\u30c9<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1c\u53d6\u5f97\uff1e<\/strong><\/span><br \/>\n    <strong>Set<\/strong> <em>recordset<\/em> = <em>object<\/em>.<strong>Execute<\/strong> [ ( <em>RecordsAffected<\/em>, <em>Parameters<\/em>, <em>Options<\/em> ) ]<\/p>\n<p>    <em>object<\/em>.<strong>Execute<\/strong> [ <em>RecordsAffected<\/em>, <em>Parameters<\/em>, <em>Options<\/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>Command \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>recordset&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u3092\u8868\u3059\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u6570\u3067\u3059\u3002<strong>Execute \u30e1\u30bd\u30c3\u30c9<\/strong>\u306e\u5b9f\u884c\u7d50\u679c\u3001\u307e\u305f\u306f\u3001<strong>Nothing<\/strong> \u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n<li>RecordsAffected&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u9577\u6574\u6570\u578b\uff08Long\uff09\u306e\u5909\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<strong>Execute \u30e1\u30bd\u30c3\u30c9<\/strong>\u5b9f\u884c\u64cd\u4f5c\u306b\u3088\u3063\u3066\u5f71\u97ff\u3092\u53d7\u3051\u305f\u30ec\u30b3\u30fc\u30c9\u306e\u6570\u3092\u3053\u306e\u5909\u6570\u306b\u8fd4\u3057\u307e\u3059\uff08\u3064\u307e\u308a\u3001\u66f4\u65b0\u30af\u30a8\u30ea\u30fb\u8ffd\u52a0\u30af\u30a8\u30ea\u30fb\u524a\u9664\u30af\u30a8\u30ea\u306a\u3069\u3067\u5909\u66f4\u306e\u3042\u3063\u305f\u30ec\u30b3\u30fc\u30c9\u306e\u6570\u3001\u7701\u7565\u53ef\uff09\u3002<\/li>\n<li>Parameters&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30af\u30a8\u30ea\u306b\u6e21\u3059\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u30d0\u30ea\u30a2\u30f3\u30c8\u578b\uff08Variant\uff09\u306e\u914d\u5217\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002\u8a73\u7d30\u306f\u3001<a href=\"https:\/\/excelwork.info\/excel\/adocommand\/#parameters\">\u30af\u30a8\u30ea\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3057\u3066\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308b\uff08ADO\uff09Command \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30fbExecute \u30e1\u30bd\u30c3\u30c9 Parameters \u30b3\u30ec\u30af\u30b7\u30e7\u30f3<\/a> \u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>Options&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<strong>CommandText \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306e\u8a55\u4fa1\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306b\u4f7f\u3044\u307e\u3059\u3002SQL\u6587\u3092\u5b9f\u884c\u3059\u308b\u306b\u306f\u3001<strong>adCmdText<\/strong> \u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u3059\u308b\u3068 <strong>adCmdUnknown<\/strong> \u304c\u6307\u5b9a\u3055\u308c\u305f\u3068\u898b\u306a\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/><br \/>\n<h3>Insert Into \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\uff08\u30ec\u30b3\u30fc\u30c9\u8ffd\u52a0\uff09\u3092\u5b9f\u884c\u3059\u308b<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306b\u30ec\u30b3\u30fc\u30c9\u3092\uff11\u3064\u8ffd\u52a0\u3057\u307e\u3059\uff08\u8ffd\u52a0\u30af\u30a8\u30ea\uff09<\/p>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <strong>INSERT INTO<\/strong> <em>target<\/em> [<em>field1<\/em>, <em>field2<\/em>, \u30fb\u30fb\u30fb ] <strong>VALUES<\/strong> ( <em>value1<\/em>, <em>value2<\/em>, \u30fb\u30fb\u30fb )<\/p><\/div>\n<br \/>\n<h4>CreateObject \u95a2\u6570<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>target&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u30fb\u30af\u30a8\u30ea\u306e\u540d\u524d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>field1, field2, \u2026&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\uff08\u5217\u540d\uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u8907\u6570\u6307\u5b9a\u3059\u308b\u5834\u5408\u306f\u30ab\u30f3\u30de\u3067\u533a\u5207\u308a\u307e\u3059\u3002<\/li>\n<li>value1, value2, \u2026&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u65b0\u898f\u306b\u8ffd\u52a0\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u306e\u5024\u306f\u3001\u8a18\u8ff0\u9806\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u633f\u5165\u3055\u308c\u307e\u3059\u3002\u3064\u307e\u308a\u3001value1 \u306f \u5217\uff08field1\uff09\u306b\u3001value2 \u306f \u5217\uff08value2\uff09\u306b\u633f\u5165\u3055\u308c\u307e\u3059\u3002\u5024\u3068\u5024\u306e\u9593\u306f\u30ab\u30f3\u30de\u3067\u533a\u5207\u308a\u3001\u30c6\u30ad\u30b9\u30c8\u306e\u5024\u306f\u5358\u4e00\u5f15\u7528\u7b26\uff08&#8217;\uff09\u3067\u56f2\u307f\u307e\u3059\u3002<\/li>\n<\/ul>\n<br \/>\n<p class=\"caution8\">Access \u306e\u5834\u5408\u3001\u4e0a\u8a18\u69cb\u6587\u3067\u306f\u4e00\u5ea6\u306b\u8907\u6570\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<\/p><\/div>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08\u30ec\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\uff09\u305d\u306e\uff11<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"INSERT INTO \u6587\uff08\u5358\u30ec\u30b3\u30fc\u30c9\u8ffd\u52a0\uff09 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Command_ExecuteInsert()\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 cmd As ADODB.Command\r\n    Dim rs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFile As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n    Dim strSQL1 As String\r\n    Dim strSQL2 As String\r\n    Dim strSQL3 As String\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    strSQL1 = \"insert into \" & _\r\n              \"\u30c6\u30fc\u30d6\u30eb4 (\u793e\u54e1ID,\u6c0f\u540d,\u30d5\u30ea\u30ac\u30ca,\u6027\u5225,\u90e8\u7f72C,\u5165\u793e\u5e74\u6708\u65e5) \" & _\r\n              \"values ('H0051','\u5de5\u85e4\u9ebb\u8863','\u30af\u30c9\u30a6\u30de\u30a4','\u5973',100,#1999\/4\/10#)\"\r\n\r\n    strSQL2 = \"insert into \" & _\r\n              \"\u30c6\u30fc\u30d6\u30eb4 (\u793e\u54e1ID,\u6c0f\u540d,\u30d5\u30ea\u30ac\u30ca,\u6027\u5225,\u90e8\u7f72C,\u5165\u793e\u5e74\u6708\u65e5) \" & _\r\n             \"values ('H0055','\u56fd\u7acb\u6d69\u53f8','\u30af\u30cb\u30bf\u30c1\u30b3\u30a6\u30b8','\u7537',105,#1999\/4\/20#)\"\r\n\r\n    strSQL3 = \"select * from \u30c6\u30fc\u30d6\u30eb4 order by \u793e\u54e1ID\"\r\n    \r\n    Set cn = New ADODB.Connection\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set cmd = New ADODB.Command\r\n    With cmd\r\n        .ActiveConnection = cn\r\n        \r\n        .CommandText = strSQL1\r\n        .Execute\r\n        \r\n        .CommandText = strSQL2\r\n        .Execute\r\n        \r\n        .CommandText = strSQL3\r\n        Set rs = .Execute\r\n    End With\r\n            \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n        \r\n    Set cmd = Nothing\r\n    Set rs = Nothing\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:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert1_01a.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert1_01a.jpg?resize=580%2C485&#038;ssl=1\" alt=\"Command.Execute Insert Into \u6587\" width=\"580\" height=\"485\" class=\"alignnone size-large wp-image-6196\" srcset=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert1_01a.jpg?resize=580%2C485&amp;ssl=1 580w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert1_01a.jpg?resize=400%2C334&amp;ssl=1 400w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert1_01a.jpg?w=657&amp;ssl=1 657w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08\u30ec\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\uff09\u305d\u306e\uff12<\/h3>\n<p>\uff11\u884c\u306e SQL\u6587\u3067\u3001\u8907\u6570\u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u306e\u4f8b\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u524d\u3082\u3063\u3066\u3001\u30c0\u30df\u30fc\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30c0\u30df\u30fc\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u3001\uff11\u3064\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n    \u3053\u3053\u3067\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u540d\u300cdummy\u300d\u3001\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\uff08\u5217\u540d\uff09\u300cAAA\u300d\uff08\u6570\u5024\u578b\uff09\u306e\u30c0\u30df\u30fc\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210<br \/>\n    <a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/dummy_table.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/dummy_table.jpg?resize=383%2C295&#038;ssl=1\" alt=\"Dummy Table\" width=\"383\" height=\"295\" class=\"alignnone size-full wp-image-6204\" data-recalc-dims=\"1\" \/><\/a><br \/>\n    \uff08\u203b\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\uff08\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6570\u3001\u578b\u7b49\uff09\u306f\u306a\u3093\u3067\u3082\u826f\u3044\u3002\u305f\u3060\u3057\u30ec\u30b3\u30fc\u30c9\u6570\u306f\uff11\u3064\u3060\u3051\u306b\u3059\u308b\u3002\uff09\n  <\/p>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"INSERT INTO \u6587\uff08\u8907\u6570\u30ec\u30b3\u30fc\u30c9\u8ffd\u52a0\uff09 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Command_ExecuteInsert2()\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 cmd As ADODB.Command\r\n    Dim rs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFile As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n    Dim strSQL1 As String\r\n    Dim strSQL2 As String\r\n    Dim rcnt 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    strSQL1 = \"insert into \u30c6\u30fc\u30d6\u30eb1(ID, NAME, CONTRY) \" & _\r\n             \"select * from \" & _\r\n             \"[ \" & _\r\n                \"select \" & _\r\n                    \"8 as ID, \" & _\r\n                    \"'hanako' as NAME, \" & _\r\n                    \"'\u65e5\u672c' as CONTRY \" & _\r\n                \"from dummy \" & _\r\n                \"union all \" & _\r\n                \"select \" & _\r\n                    \"9 as ID, \" & _\r\n                    \"'tom' as NAME, \" & _\r\n                    \"'\u30a2\u30e1\u30ea\u30ab' as CONTRY \" & _\r\n                \"from dummy \" & _\r\n            \"]. as Qtmp\"                          \r\n        \r\n    strSQL2 = \"select * from \u30c6\u30fc\u30d6\u30eb1 order by ID\"\r\n    \r\n    Set cn = New ADODB.Connection\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set cmd = New ADODB.Command\r\n    With cmd\r\n        .ActiveConnection = cn\r\n        \r\n        .CommandText = strSQL1\r\n        .Execute rcnt\r\n                \r\n        .CommandText = strSQL2\r\n        Set rs = .Execute\r\n    End With\r\n            \r\n    MsgBox rcnt & \" \u30ec\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\"\r\n            \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n        \r\n    Set cmd = Nothing\r\n    Set rs = Nothing\r\n    cn.Close\r\n    Set cn = Nothing\r\n\r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<p class=\"caution4\">strSQL1 \u306b\u3064\u3044\u3066\uff0820\u884c\u76ee\uff5e34\u884c\u76ee\uff09<br \/>\n    20\u884c\u76ee\uff1aINSERT INTO [\u30c6\u30fc\u30d6\u30eb\u540d] ( [\u5217\u540d1], [\u5217\u540d2], \u30fb\u30fb\u30fb )<br \/>\n    23\u884c\u76ee\uff1a\uff11\u3064\u76ee\u306e\u8ffd\u52a0\u3059\u308b\u30ec\u30b3\u30fc\u30c9\uff08\uff5e27\u884c\u76ee\uff09<br \/>\n    24\u884c\u76ee\uff1a8 as ID,\u3000\u2192\u3000[\u30c7\u30fc\u30bf] as [\u5217\u540d]<br \/>\n    25\u884c\u76ee\uff1a&#8217;hanako&#8217; as NAME,\u3000\u2192\u3000[\u30c7\u30fc\u30bf] as [\u5217\u540d]<br \/>\n    26\u884c\u76ee\uff1a&#8217;\u65e5\u672c&#8217; as CONTRY\u3000\u2192\u3000[\u30c7\u30fc\u30bf] as [\u5217\u540d]<br \/>\n    29\u884c\u76ee\uff1a\uff12\u3064\u76ee\u306e\u8ffd\u52a0\u3059\u308b\u30ec\u30b3\u30fc\u30c9\uff08\uff5e33\u884c\u76ee\uff09<br \/>\n    \uff08\u203b\u3000\uff11\u3064\u76ee\u306e\u30ec\u30b3\u30fc\u30c9\u3068\uff12\u3064\u76ee\u306e\u30ec\u30b3\u30fc\u30c9\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u63c3\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff09<br \/>\n    34\u884c\u76ee\uff1a&#8221;]. as Qtmp&#8221;\u3000\u2192\u3000\u300c.\u300d\u306f\u5fc5\u8981\u3067\u3059\u3002\u300cQtmp\u300d\u4efb\u610f\u306e\u540d\u524d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\n  <\/p>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p>  <a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert2_01.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert2_01.jpg?resize=161%2C148&#038;ssl=1\" alt=\"Command.Execute Insert Into \u6587 \uff08\u8907\u6570\uff09\" width=\"161\" height=\"148\" class=\"alignnone size-full wp-image-6197\" data-recalc-dims=\"1\" \/><\/a><br \/>\n  <br \/>\n<a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/09\/command.execute_insert2_02b.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/09\/command.execute_insert2_02b.jpg?resize=275%2C334&#038;ssl=1\" alt=\"Command.Execute Insert Into \u6587 \uff08\u8907\u6570\uff092\" width=\"275\" height=\"334\" class=\"alignnone size-full wp-image-6366\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3>UPDATE \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\uff08\u30ec\u30b3\u30fc\u30c9\u5909\u66f4\uff09\u3092\u5b9f\u884c\u3059\u308b<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <strong>UPDATE<\/strong> <em>target<\/em> <strong>SET<\/strong> <em>newvalue<\/em> <strong>WHERE<\/strong> <em>criteria<\/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>target&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5909\u66f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u30c6\u30fc\u30d6\u30eb\u30fb\u30af\u30a8\u30ea\u306e\u540d\u524d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>newvalue&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5909\u66f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\uff08\u5217\u540d\uff09\u3001\u5024\u3092\u8868\u3059\u305f\u3081\u306e\u5f0f\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>criteria&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u62bd\u51fa\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u6307\u5b9a\u3055\u308c\u305f\u6761\u4ef6\u3092\u6e80\u305f\u3059\u30ec\u30b3\u30fc\u30c9\u306e\u307f\u304c\u5909\u66f4\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08\u30ec\u30b3\u30fc\u30c9\u306e\u66f4\u65b0\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Update \u6587\uff08\u30ec\u30b3\u30fc\u30c9\u66f4\u65b0\uff09 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Command_ExecuteUpdate()\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 cmd As ADODB.Command\r\n    Dim rs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFile As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n    Dim strSQL1 As String\r\n    Dim strSQL2 As String\r\n    Dim rcnt 'RecordsAffected\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    strSQL1 = \"update \u30c6\u30fc\u30d6\u30eb4 \" & _\r\n             \"set \u90e8\u7f72C = 106 where \u90e8\u7f72C = 200\"\r\n\r\n    strSQL2 = \"select * from \u30c6\u30fc\u30d6\u30eb4 order by \u793e\u54e1ID\"\r\n    \r\n    Set cn = New ADODB.Connectionpp\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set cmd = New ADODB.Command\r\n    With cmd\r\n        .ActiveConnection = cn\r\n        \r\n        .CommandText = strSQL1\r\n        .Execute rcnt\r\n        \r\n        .CommandText = strSQL2\r\n        Set rs = .Execute\r\n    End With\r\n    \r\n    MsgBox rcnt & \" \u306e\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\"\r\n            \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n        \r\n    Set cmd = Nothing\r\n    Set rs = Nothing\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:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_01.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_01.jpg?resize=170%2C148&#038;ssl=1\" alt=\"Command.Execute Update \u6587 1\" width=\"170\" height=\"148\" class=\"alignnone size-full wp-image-6199\" data-recalc-dims=\"1\" \/><\/a><br \/>\n  <br \/>\n  <a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_02b.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_02b.jpg?resize=580%2C482&#038;ssl=1\" alt=\"Command.Execute Update \u6587 2\" width=\"580\" height=\"482\" class=\"alignnone size-large wp-image-6200\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_02b.jpg?resize=580%2C482&amp;ssl=1 580w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_02b.jpg?resize=400%2C333&amp;ssl=1 400w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_update1_02b.jpg?w=658&amp;ssl=1 658w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3>DELETE \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\uff08\u30ec\u30b3\u30fc\u30c9\u524a\u9664\uff09\u3092\u5b9f\u884c\u3059\u308b<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <strong>DELETE<\/strong> <strong>FROM<\/strong> <em>table<\/em> <strong>WHERE<\/strong> <em>criteria<\/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>table&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u524a\u9664\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>criteria&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u62bd\u51fa\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u6307\u5b9a\u3055\u308c\u305f\u6761\u4ef6\u3092\u6e80\u305f\u3059\u30ec\u30b3\u30fc\u30c9\u306e\u307f\u304c\u524a\u9664\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/>\n<p class=\"caution4\">\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Delete \u6587\uff08\u30ec\u30b3\u30fc\u30c9\u524a\u9664\uff09 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Command_ExecuteDelete()\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 cmd As ADODB.Command\r\n    Dim rs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFile As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n    Dim strSQL As String\r\n    Dim strSQL2 As String\r\n    Dim rcnt 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    strSQL = \"delete from \u30c6\u30fc\u30d6\u30eb4 \" & _\r\n             \"where \u793e\u54e1ID in('H0051','H0055')\"\r\n    strSQL2 = \"select * from \u30c6\u30fc\u30d6\u30eb4 order by \u793e\u54e1ID\"\r\n    \r\n    Set cn = New ADODB.Connection\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set cmd = New ADODB.Command\r\n    With cmd\r\n        .ActiveConnection = cn\r\n        .CommandText = strSQL\r\n        .Execute RecordsAffected:=rcnt\r\n        .CommandText = strSQL2\r\n        Set rs = .Execute\r\n    End With\r\n    \r\n    MsgBox rcnt & \" \u306e\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002\"\r\n        \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n        \r\n    Set cmd = Nothing\r\n    Set rs = Nothing\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\/command.execute_delete1_01.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_delete1_01.jpg?resize=172%2C148&#038;ssl=1\" alt=\"Command.Execute Delete \u6587 1\" width=\"172\" height=\"148\" class=\"alignnone size-full wp-image-6201\" data-recalc-dims=\"1\" \/><\/a><br \/>\n  <br \/>\n  <a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_delete1_02a.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_delete1_02a.jpg?resize=580%2C486&#038;ssl=1\" alt=\"Command.Execute Delete \u6587 2\" width=\"580\" height=\"486\" class=\"alignnone size-large wp-image-6202\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_delete1_02a.jpg?resize=580%2C486&amp;ssl=1 580w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_delete1_02a.jpg?resize=400%2C335&amp;ssl=1 400w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_delete1_02a.jpg?w=658&amp;ssl=1 658w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n<h2>Connection \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e Execute \u30e1\u30bd\u30c3\u30c9\u3067\u3001SQL\u6587\u3092\u5b9f\u884c<\/h2>\n<div class=\"m30-l\">\n<p><strong>Connection \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u3067 <strong>Execute \u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001<strong>CommandText \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u6307\u5b9a\u3057\u305fSQL\u6587\u3084\u30af\u30a8\u30ea\u7b49\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<strong>CommandText \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u7d50\u679c\u3092\u8fd4\u3059 SQL\u6587\u3084\u30af\u30a8\u30ea\u7b49\u304c\u6307\u5b9a\u3055\u308c\u305f\u5834\u5408\u3001\u65b0\u898f\u306e <strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3 id=\"connection_execute\">Connection.Execute \u30e1\u30bd\u30c3\u30c9<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1c\u53d6\u5f97\uff1e<\/strong><\/span><br \/>\n    <strong>Set<\/strong> <em>recordset<\/em> = <em>object<\/em>.<strong>Execute<\/strong> [ ( <em>CommandText<\/em>, <em>RecordsAffected<\/em>, <em>Options<\/em> ) ]<\/p>\n<p>    <em>object<\/em>.<strong>Execute<\/strong> [ <em>CommandText<\/em>, <em>RecordsAffected<\/em>, <em>Options<\/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>Connection \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>recordset&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u3092\u8868\u3059\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u6570\u3067\u3059\u3002<strong>Execute \u30e1\u30bd\u30c3\u30c9<\/strong>\u306e\u5b9f\u884c\u7d50\u679c\u3001\u307e\u305f\u306f\u3001<strong>Nothing<\/strong> \u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n<li>CommandText&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5b9f\u884c\u3059\u308b SQL\u6587\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>RecordsAffected&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u9577\u6574\u6570\u578b\uff08Long\uff09\u306e\u5909\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<strong>Execute \u30e1\u30bd\u30c3\u30c9<\/strong>\u5b9f\u884c\u64cd\u4f5c\u306b\u3088\u3063\u3066\u5f71\u97ff\u3092\u53d7\u3051\u305f\u30ec\u30b3\u30fc\u30c9\u306e\u6570\u3092\u3053\u306e\u5909\u6570\u306b\u8fd4\u3057\u307e\u3059\uff08\u3064\u307e\u308a\u3001\u66f4\u65b0\u30af\u30a8\u30ea\u30fb\u8ffd\u52a0\u30af\u30a8\u30ea\u30fb\u524a\u9664\u30af\u30a8\u30ea\u306a\u3069\u3067\u5909\u66f4\u306e\u3042\u3063\u305f\u30ec\u30b3\u30fc\u30c9\u306e\u6570\u3001\u7701\u7565\u53ef\uff09\u3002<\/li>\n<li>Options&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<strong>CommandText \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306e\u8a55\u4fa1\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306b\u4f7f\u3044\u307e\u3059\u3002\u7701\u7565\u3059\u308b\u3068 <strong>adCmdUnknown<\/strong> \u304c\u6307\u5b9a\u3055\u308c\u305f\u3068\u898b\u306a\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08Select\u6587\u306e\u5b9f\u884c\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Select \u6587 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Connection_ExecuteSQL()\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    strSQL = \"select * from \u30c6\u30fc\u30d6\u30eb4 where \u6027\u5225='\u7537' and \u90e8\u7f72C=106\"\r\n    \r\n    Set cn = New ADODB.Connection\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set rs = cn.Execute(strSQL)\r\n    \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n    \r\n    Set rs = Nothing\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:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_select01.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_select01.jpg?resize=580%2C239&#038;ssl=1\" alt=\"Connection.Execute \u30e1\u30bd\u30c3\u30c9 Select\u6587\" width=\"580\" height=\"239\" class=\"alignnone size-large wp-image-6209\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_select01.jpg?resize=580%2C239&amp;ssl=1 580w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_select01.jpg?resize=400%2C165&amp;ssl=1 400w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_select01.jpg?w=637&amp;ssl=1 637w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08Insert Into\u6587\u306e\u5b9f\u884c\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Insert Into \u6587 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Connection_ExecuteInsert()\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 i As Long\r\n    Dim j As Long\r\n    Dim strSQL1 As String\r\n    Dim strSQL2 As String\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    strSQL1 = \"insert into \" & _\r\n              \"\u30c6\u30fc\u30d6\u30eb4 (\u793e\u54e1ID,\u6c0f\u540d,\u30d5\u30ea\u30ac\u30ca,\u6027\u5225,\u90e8\u7f72C,\u5165\u793e\u5e74\u6708\u65e5) \" & _\r\n              \"values ('H0053','\u7b39\u539f\u3084\u3088\u3044','\u30b5\u30b5\u30cf\u30e9\u30e4\u30e8\u30a4','\u5973',100,#1999\/12\/10#)\"\r\n\r\n    strSQL2 = \"select * from \u30c6\u30fc\u30d6\u30eb4 where \u793e\u54e1ID like 'H005%'\"\r\n    \r\n    Set cn = New ADODB.Connection\r\n    \r\n    With cn\r\n    \r\n        .ConnectionString = constr\r\n        .Open\r\n        \r\n        .Execute strSQL1\r\n        Set rs = .Execute(strSQL2)\r\n    \r\n    End With\r\n            \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n        \r\n    Set rs = Nothing\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:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_insert01.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_insert01.jpg?resize=580%2C233&#038;ssl=1\" alt=\"Connection.Execute \u30e1\u30bd\u30c3\u30c9 Insert Into \u6587\" width=\"580\" height=\"233\" class=\"alignnone size-large wp-image-6210\" srcset=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_insert01.jpg?resize=580%2C233&amp;ssl=1 580w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_insert01.jpg?resize=400%2C160&amp;ssl=1 400w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_insert01.jpg?w=658&amp;ssl=1 658w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9\uff08Delete\u6587\u306e\u5b9f\u884c\uff09<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Delete \u6587 \u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Connection_ExecuteDelete()\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 i As Long\r\n    Dim j As Long\r\n    Dim strSQL1 As String\r\n    Dim strSQL2 As String\r\n    Dim rcnt 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    strSQL1 = \"delete from \u30c6\u30fc\u30d6\u30eb4 \" & _\r\n             \"where \u6c0f\u540d like '\u7b39\u539f%'\"\r\n    strSQL2 = \"select * from \u30c6\u30fc\u30d6\u30eb4 where \u793e\u54e1ID like 'H005%' order by \u793e\u54e1ID\"\r\n    \r\n    Set cn = New ADODB.Connection\r\n    \r\n    With cn\r\n        .ConnectionString = constr\r\n        .Open\r\n        \r\n        .Execute strSQL1, rcnt\r\n        Set rs = .Execute(strSQL2)\r\n    End With\r\n        \r\n    MsgBox rcnt & \" \u500b\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002\"\r\n        \r\n    With Worksheets(\"Sheet1\")\r\n        .Cells.Clear\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        .Columns(\"A:H\").AutoFit\r\n    End With\r\n        \r\n    Set rs = Nothing\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\/connection.execute_delete01.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_delete01.jpg?resize=191%2C148&#038;ssl=1\" alt=\"Connection.Execute \u30e1\u30bd\u30c3\u30c9 Delete\u65871\" width=\"191\" height=\"148\" class=\"alignnone size-full wp-image-6211\" data-recalc-dims=\"1\" \/><\/a><br \/>\n  <br \/>\n  <a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_delete02.jpg?ssl=1\" rel=\"lightbox[6188]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_delete02.jpg?resize=580%2C239&#038;ssl=1\" alt=\"Connection.Execute \u30e1\u30bd\u30c3\u30c9 Delete\u65872\" width=\"580\" height=\"239\" class=\"alignnone size-large wp-image-6212\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_delete02.jpg?resize=580%2C239&amp;ssl=1 580w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_delete02.jpg?resize=400%2C165&amp;ssl=1 400w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/connection.execute_delete02.jpg?w=633&amp;ssl=1 633w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>Command \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e Execute \u30e1\u30bd\u30c3\u30c9\u3067\u3001SQL\u6587\u3092\u5b9f\u884c Co &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6196,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[953,950,989,966,721,1002,968,996,1000,999,951,1001,814,955,949,835],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/command.execute_insert1_01a.jpg?fit=657%2C549&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1BO","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6188"}],"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=6188"}],"version-history":[{"count":21,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6188\/revisions"}],"predecessor-version":[{"id":6484,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6188\/revisions\/6484"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6196"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}