{"id":122,"date":"2006-10-02T02:23:46","date_gmt":"2006-10-02T02:23:46","guid":{"rendered":"http:\/\/search.jason695.idv.tw:81\/wordpress\/?p=122"},"modified":"2008-05-15T17:09:15","modified_gmt":"2008-05-15T09:09:15","slug":"%e5%8f%af%e6%83%a1%e7%9a%84begintransaction","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2006\/10\/02\/%e5%8f%af%e6%83%a1%e7%9a%84begintransaction\/","title":{"rendered":"\u53ef\u60e1\u7684BeginTransaction"},"content":{"rendered":"<pre lang=\"VBNET\" line=\"1\">\r\nPublic Sub RunSqlTransaction(myConnString As String)\r\nDim myConnection As New SqlConnection(myConnString)\r\nmyConnection.Open()\r\n\r\nDim myCommand As SqlCommand = myConnection.CreateCommand()\r\nDim myTrans As SqlTransaction\r\n\r\n' Start a local transaction\r\nmyTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted, \"SampleTransaction\")\r\n' Must assign both transaction object and connection\r\n' to Command object for a pending local transaction\r\nmyCommand.Connection = myConnection\r\nmyCommand.Transaction = myTrans\r\n\r\nTry\r\nmyCommand.CommandText = \"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')\"\r\nmyCommand.ExecuteNonQuery()\r\nmyCommand.CommandText = \"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')\"\r\nmyCommand.ExecuteNonQuery()\r\nmyTrans.Commit()\r\nConsole.WriteLine(\"Both records are written to database.\")\r\nCatch e As Exception\r\nTry\r\nmyTrans.Rollback(\"SampleTransaction\")\r\nCatch ex As SqlException\r\nIf Not myTrans.Connection Is Nothing Then\r\nConsole.WriteLine(\"An exception of type \" &amp; ex.GetType().ToString() &amp; _\r\n\" was encountered while attempting to roll back the transaction.\")\r\nEnd If\r\nEnd Try\r\n\r\nConsole.WriteLine(\"An exception of type \" &amp; e.GetType().ToString() &amp; _\r\n\"was encountered while inserting the data.\")\r\nConsole.WriteLine(\"Neither record was written to database.\")\r\nFinally\r\nmyConnection.Close()\r\nEnd Try\r\nEnd Sub 'RunSqlTransaction\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Public Sub RunSqlTransaction(myConnString As String) Di &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2006\/10\/02\/%e5%8f%af%e6%83%a1%e7%9a%84begintransaction\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">\u53ef\u60e1\u7684BeginTransaction<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","hentry","category-net","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}