• 首页
  • 小学语文
  • 中学语文
  • 中学英语
  • 免费论文
  • 教学随笔
  • 学生作文
  • 综合考试
  • 试题教案
  • 育儿话题
  • 教学资源
  • 编程技术
  • 博客
  • 建立一个连接数据库的VB组件

    日期:2005-05-11  地址:  作者:
    建立一个连接数据库的VB组件
    http://www.tongyi.net  作者:slash  出处:www.51dotnet.com    点击:2082  

    首先在你的config.web 文件中创建以下参数:
    <appsettings>
    <add key="gConn" value="server=local;uid=sa;pwd=secret;database=pubs" />
    </appsettings>

    接着建立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 文件:

    <%@ Page Description="ASP+ document" EnableSessionState="false" MaintainState="false" %>
    <%@ Import Namespace="WebDB" %>
    <script language="VB" runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)

    response.write(WebDBconn.ConnectionString)

    End Sub

    </script>

    <html>
    <head>
    <title></title>
    </head>
    <body>
    </body>
    </html>

    对 建立一个连接数据库的VB组件 文章的评论    [查看网友评论]

    验证码:
    匿名发表: