Create a VB component connecting the database

zhaozj2021-02-11  182

Create a VB component connecting the database

http://www.tongyi.net Author: slash Source: www.51dotnet.com Hits: 2082

First create the following parameters in your config.Web file: then established Dbconn.vb file. Imports SystemImports System.WebImports System.CollectionsNamespace WebDBPublic Class WebDBconn Shared m_ConnectionString As StringShared ReadOnly Property ConnectionString As String Get If m_ConnectionString = "" ThenDim appsetting As Hashtable = CType (HttpContext.Current.GetConfig ( "appsettings"), Hashtable) 'using config. in the establishment of a good web connection string m_ConnectionString = CStr (appsetting ( "DBConnString")) If m_ConnectionString = "" Thenthrow new Exception ( "Dtabase connection Value not set in Config.web") End ifEnd If 'return connection string return m_connectionStringEnd Getend Propertyend Classend Namespace 'The following compiles the DLL file: Create a batch file, named Makedll.bat, store the same directory in dbconn.vb, where SET ODIR = dbconn.dllset assemblies = system.Web.dllvbc / t : library / out:% ODIR% / R:% assemblyMBlies% dbconn.vb Execute batch files, copy dbconn.dll to your web directory BIN directory and create the following .aspx file: <% @ page description = "ASP document" EnableSessionState = "false" MaintainState = "false"%> <% @ Import Namespace = "WebDB"%>