http://www.tongyi .NET 作者:slash 出处:www.51 dotnet.com 点击:2082
首先在你的config.web 文件中创建以下参数:
接着建立dbConn.vb 文件。
Imports System
Imports System.Web
Imports System.Collections
Namespace WebDB
Public Class WebDBconn
Shared m_ConnectionString As String
Shared ReadOnly Property ConnectionString As String
Get
If m_ConnectionString = "" Then
Dim appsetting As Hashtable = CType(HttpContext.Current.GetConfig("appsettings"), Hashtable)
'使用 config.web 中设立好的连接字符串
m_ConnectionString = CStr(appsetting("DBConnString"))
If m_ConnectionString = "" Then
throw new Exception("Dtabase Connection Value not set in Config.web")
End if
End If
' 返回连接字符串
return m_connectionString
End Get
End Property
End Class
End Namespace
'下面编译dll文件:创建一个批处理文件, 命名为 MakeDll.bat ,存放在dbConn.vb 相同的目录,其中的内容如下
set odir=dbConn.dll
set assemblies=System.Web.dll
vbc /t:library /out:%odir% /r:%assemblies% dbConn.vb
执行批处理文件, 将 dbconn.dll 拷贝到你的WEB 目录的 BIN 目录下并创建如下的.ASPx 文件:
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-989602/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-989602/
本文介绍如何使用VB创建一个连接数据库的组件。通过设置config.web文件中的参数,并编写dbConn.vb文件来实现数据库连接功能。文章还提供了编译DLL文件的具体步骤。

被折叠的 条评论
为什么被折叠?



