{"id":3011,"date":"2013-03-14T10:32:50","date_gmt":"2013-03-14T02:32:50","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=3011"},"modified":"2017-10-23T06:24:08","modified_gmt":"2017-10-22T22:24:08","slug":"visual-basic-2010-lesson-31","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/","title":{"rendered":"Visual Basic 2010 Lesson 31: Managing Databases"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-30\/\">[Lesson 30]<\/a>\u00a0<\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a><\/strong>&gt;&gt;<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/vb2010me\/\">[Next]<\/a><\/strong><\/h4>\n<h2><strong>31.1 Browsing Records in Databases\u00a0<\/strong><\/h2>\n<p>In this lesson, we will create command buttons and write relevant codes to allow the user to browse the records forward and backward as well as fast forward to the last record and back to the first record.The first button we need to create is for the user to browse the first record. We can use button&#8217;s text <strong>&lt;&lt;\u00a0<\/strong>to indicate to the user that it is the button to move to the first record and button&#8217;s text &gt;&gt; to move to the last record. \u00a0Besides we can use button&#8217;s text &lt; \u00a0for moving to previous record and button&#8217;s text &gt; \u00a0for moving to next record.<br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nThe code for moving to the first record is as follows:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\"><strong>MyRowPosition = 0<\/strong>\r\n<strong> Me.showRecords()<\/strong>\r\n<\/pre>\n<p>The code for moving to the previous record is:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\"><strong>If MyRowPosition &gt; 0 Then<\/strong>\r\n<strong> MyRowPosition = MyRowPosition - 1<\/strong>\r\n<strong> Me.showRecords()<\/strong>\r\n<strong> End If<\/strong>\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nThe code for moving to next record is:<\/p>\n<pre style=\"font-size: 110%;\"><strong>If MyRowPosition &lt; (MyDataTbl.Rows.Count - 1) Then<\/strong>\r\n<strong> MyRowPosition = MyRowPosition + 1<\/strong>\r\n<strong> Me.showRecords()<\/strong>\r\n<strong>End If<\/strong>\r\n<\/pre>\n<p>The code for moving to the last record is:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\"><strong>If MyDataTbl.Rows.Count &gt; 0 Then<\/strong>\r\n<strong> MyRowPosition = MyDataTbl.Rows.Count - 1<\/strong>\r\n<strong> Me.showRecords()<\/strong>\r\n<strong> End If<\/strong>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2><strong>31.2 \u00a0Editing, Saving, Adding and Deleting Records<\/strong><\/h2>\n<p>You can edit any record by navigating to the record and change the data values. However, you need to save the data after editing them. You need to use the update method of the SqlDataAdapter to save the data. The code \u00a0is:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\"><strong>If MyDataTbl.Rows.Count &lt;&gt; 0 Then<\/strong>\r\n<strong>MyDataTbl.Rows(MyRowPosition)(\"ContactName\") = txtName.Text<\/strong>\r\n<strong> MyDataTbl.Rows(MyRowPosition)(\"state\") = txtState.Text<\/strong>\r\n<strong> MyDatAdp.Update(MyDataTbl)<\/strong>\r\n<strong> End If<\/strong>\r\n<\/pre>\n<p>You can also add a new record or new row to the table using the following code:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\"><strong>Dim MyNewRow As DataRow = MyDataTbl.NewRow()<\/strong>\r\n<strong> MyDataTbl.Rows.Add(MyNewRow)<\/strong>\r\n<strong> MyRowPosition = MyDataTbl.Rows.Count - 1<\/strong>\r\n<strong> Me.showRecords()<\/strong>\r\n<\/pre>\n<p>The code above will present a new record with blank fields for the user to enter the new data. After entering the data, he or she can then click the save button to save the data.<\/p>\n<p>Lastly, the user might want to delete the data. The code to delete the data is:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\"><strong>If MyDataTbl.Rows.Count &lt;&gt; 0 Then<\/strong>\r\n<strong> MyDataTbl.Rows(MyRowPosition).Delete()<\/strong>\r\n<strong> MyDatAdp.Update(MyDataTbl)<\/strong>\r\n<strong> MyRowPosition = 0<\/strong>\r\n<strong> Me.showRecords()<\/strong>\r\n<strong> End If<\/strong>\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"8075128701\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\">\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-30\/\">[Lesson 30]<\/a>\u00a0<\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a><\/strong>&gt;&gt;<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/vb2010me\/\">[Next]<\/a><\/strong><\/h4>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 30]\u00a0&lt;&lt;\u00a0[CONTENTS]&gt;&gt;[Next] 31.1 Browsing Records in Databases\u00a0 In this lesson, we will create command buttons and write relevant codes to allow the user to browse the records forward and backward as well as fast forward to the last record and back to the first record.The first button we need to create is for the user &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2010 Lesson 31: Managing Databases<\/span><\/a><\/p>\n","protected":false},"author":23013,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-3011","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visual Basic 2010 Lesson 31: Managing Databases - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This visual basic 2010 lesson illustrates the manipulation of data in databases\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2010 Lesson 31: Managing Databases - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This visual basic 2010 lesson illustrates the manipulation of data in databases\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Vbtutor\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-22T22:24:08+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@liewvk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/\",\"url\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/\",\"name\":\"Visual Basic 2010 Lesson 31: Managing Databases - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"datePublished\":\"2013-03-14T02:32:50+00:00\",\"dateModified\":\"2017-10-22T22:24:08+00:00\",\"description\":\"This visual basic 2010 lesson illustrates the manipulation of data in databases\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2010 Lesson 31: Managing Databases\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vbtutor.net\/#website\",\"url\":\"https:\/\/www.vbtutor.net\/\",\"name\":\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"description\":\"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visual Basic 2010 Lesson 31: Managing Databases - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This visual basic 2010 lesson illustrates the manipulation of data in databases","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2010 Lesson 31: Managing Databases - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This visual basic 2010 lesson illustrates the manipulation of data in databases","og_url":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/","og_site_name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","article_publisher":"https:\/\/www.facebook.com\/Vbtutor","article_modified_time":"2017-10-22T22:24:08+00:00","twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/","url":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/","name":"Visual Basic 2010 Lesson 31: Managing Databases - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"datePublished":"2013-03-14T02:32:50+00:00","dateModified":"2017-10-22T22:24:08+00:00","description":"This visual basic 2010 lesson illustrates the manipulation of data in databases","breadcrumb":{"@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-31\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2010 Lesson 31: Managing Databases"}]},{"@type":"WebSite","@id":"https:\/\/www.vbtutor.net\/#website","url":"https:\/\/www.vbtutor.net\/","name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/3011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/users\/23013"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=3011"}],"version-history":[{"count":39,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/3011\/revisions"}],"predecessor-version":[{"id":12507,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/3011\/revisions\/12507"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=3011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=3011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=3011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}