{"id":376,"date":"2018-02-13T14:46:38","date_gmt":"2018-02-13T19:46:38","guid":{"rendered":"http:\/\/techref.camellarry.com\/?p=376"},"modified":"2018-02-13T14:46:38","modified_gmt":"2018-02-13T19:46:38","slug":"vb-net-module-for-sql-database","status":"publish","type":"post","link":"http:\/\/techref.camellarry.com\/?p=376","title":{"rendered":"VB.NET Module for SQL Database"},"content":{"rendered":"<p>Imports System.Data.SqlClient<\/p>\n<p><strong><span style=\"color: #0000ff;\">Module modDatabase<\/span><\/strong><\/p>\n<p>Public conn As New SqlClient.SqlConnection<br \/>\nPublic myReader As SqlDataReader<\/p>\n<p>Public dsRecords As New DataSet<br \/>\nPublic daRecords As New SqlDataAdapter<br \/>\nPublic MaxRecords As Integer<\/p>\n<blockquote><p><strong>Public Sub OpenDatabase()<\/strong><br \/>\nCloseSQLReader()<br \/>\nCloseDatabase()<\/p>\n<p>conn.ConnectionString = &#8220;Server=.\\sqlexpress;Database=DATABASE;Trusted_Connection=True;&#8221;<br \/>\nconn.Open()<br \/>\n<strong>End Sub<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Public Sub CloseDatabase()<\/strong><br \/>\nTry<br \/>\nconn.Close()<br \/>\nconn.Dispose()<br \/>\nCatch ex As Exception<br \/>\nApplication.DoEvents()<br \/>\nEnd Try<br \/>\n<strong>End Sub<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Public Sub launchBrowser(ByVal browser As String, ByVal url As String)<\/strong><br \/>\nTry<br \/>\nProcess.Start(browser, url)<br \/>\nCatch ex As Exception<br \/>\nApplication.DoEvents()<br \/>\n&#8216;MessageBox.Show(ex.Message)<br \/>\nEnd Try<br \/>\n<strong>End Sub<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Public Sub CloseSQLReader()<\/strong><br \/>\nTry<br \/>\nmyReader.Close()<br \/>\nCatch ex As Exception<br \/>\nApplication.DoEvents()<br \/>\nEnd Try<br \/>\n<strong>End Sub<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Public Sub ReadSqlData(ByVal sqlSelect As String)<\/strong><br \/>\nDim myCommand As New SqlCommand(sqlSelect, conn)<br \/>\nmyReader = myCommand.ExecuteReader()<br \/>\n<strong>End Sub<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Public Function ExecuteSqlCommand(ByVal sqlSelect As String) As Boolean<\/strong><br \/>\nDim flg As Boolean = False<br \/>\nDim myCommand As New SqlCommand(sqlSelect, conn)<\/p>\n<p>Try<br \/>\nflg = myCommand.ExecuteNonQuery<br \/>\nCatch<br \/>\nflg = False<br \/>\nEnd Try<\/p>\n<p>Return flg<br \/>\n<strong>End Function<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Public Sub HoldYourPants(ByVal Seconds As Integer)<\/strong><br \/>\nSystem.Threading.Thread.Sleep(Seconds * 1000)<br \/>\nApplication.DoEvents()<br \/>\n<strong>End Sub<\/strong><\/p><\/blockquote>\n<p><strong><span style=\"color: #0000ff;\">End Module<\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imports System.Data.SqlClient Module modDatabase Public conn As New SqlClient.SqlConnection Public myReader As SqlDataReader Public dsRecords As New DataSet Public daRecords As New SqlDataAdapter Public MaxRecords As Integer Public Sub OpenDatabase() CloseSQLReader() CloseDatabase() conn.ConnectionString = &#8220;Server=.\\sqlexpress;Database=DATABASE;Trusted_Connection=True;&#8221; conn.Open() End Sub &nbsp; Public Sub CloseDatabase() Try conn.Close() conn.Dispose() Catch ex As Exception Application.DoEvents() End Try End Sub &nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8,9],"tags":[12,94,29,45,58,70,72,74,76,77,78,80],"class_list":["post-376","post","type-post","status-publish","format-standard","hentry","category-sql","category-vb-net","tag-net","tag-database","tag-example","tag-microsoft","tag-programming","tag-sql","tag-syntax","tag-tutorial","tag-vb","tag-vb-net","tag-visualbasic","tag-windows"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9t3oE-64","_links":{"self":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=376"}],"version-history":[{"count":1,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/376\/revisions"}],"predecessor-version":[{"id":377,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/376\/revisions\/377"}],"wp:attachment":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=376"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}