您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
连接SQL SERVER的公共类(VB.NET)
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 12:26:58

*************************************************************************
'//开始日期:2002年5月27日

'//结束日期:2002年5月27日

'***********************************************************************

Option Explicit On 

'Option Strict On

'//***********************************************************************
Imports System.Data.SqlClient


'//*************************************************************************

'//Begin defined namespace

Namespace Sunerp.CommClass.Comm


    '//Defined Structure  PublicApplicationVal

    '//Structure descriptoin

    '//本结构存取 数据库服务器名(Dbserver)、数据库用户ID(UserId)、

    '//数据库用户密码(UserPWD)、数据库名(Dbase),为联接数据库提供参数。

    '//为了满足某些简单查询的需要,提供了扩展的变量 常用表名(DBTable)、

    '//查询字段名(QueryFieldName)、查询字段值


    '//Begin define Structure PublicApplicationVal

    Public Structure PublicApplicationVal

        ' Public Dbserver, UserId UserPWD Dbase DBTable Account.

        Public Dbserver As String

        Public UserId As String

        Public UserPWD As String

        Public Dbase As String

        Public DBTable As String

        Public QueryFieldVale As String

        Public QueryFieldName As String

    End Structure

    '//End define Structure PublicApplicationVal

    '//********************************************************************

    '//Begin defined Class

    Public Class DBaseBindComm

        '*****************************************************************

        '//**定义连接SQL Server Database的通用函数**//

        '//本函数创建一个到指定数据库的连接对象 SqlConnection 

        '//本函数有1个参数,IPublicApplication 为公共数据结构 PublicApplicationVal,


        '//Begin define Function LinkedSqlServer

        Public Overloads Function LinkedSqlServer() As System.Data.SqlClient.SqlConnection


            Dim strconn As String

            Dim conn As New SqlConnection()

            strconn = "server=" & "erp" & _

                      ";user id=" & "erpsa" & _

                      ";password=" & "erpsa" & _

                      ";database=" & "erpdata" & ";"


            Try

                conn = New SqlConnection(strconn)

                conn.Open()

                StateVal = True

                LinkedSqlServer = conn

            Catch ex As Exception

                ' MsgBox(ex.ToString)

                StateVal = False

                LinkedSqlServer = Nothing

                Exit Function

            End Try

        End Function

 

        'End defined LinkedSqlServer

        '***********************************************************************

        '//**定义连接SQL Server Database的通用函数**//

        '//本函数创建一个到指定数据库的连接对象 SqlConnection 

        '//本函数有1个参数,IPublicApplication 为公共数据结构 PublicApplicationVal,


        '//Begin define Function LinkedSqlServer

        Public Overloads Function LinkedSqlServer( _

                 ByVal IPublicApplication As PublicApplicationVal) _

                 As System.Data.SqlClient.SqlConnection


            Dim strconn As String

            Dim conn As New SqlConnection()

            strconn = "server=" & IPublicApplication.Dbserver & _

                      ";user id=" & IPublicApplication.UserId & _

                      ";password=" & IPublicApplication.UserPWD & _

                      ";database=" & IPublicApplication.Dbase & ";"


            Try

                conn = New SqlConnection(strconn)

                conn.Open()

                StateVal = True

                LinkedSqlServer = conn

            Catch ex As Exception

                ' MsgBox(ex.ToString)

                StateVal = False

                LinkedSqlServer = Nothing

                Exit Function

            End Try

        End Function

        'End defined LinkedSqlServer

        '**************************************************************

 

        '定义类DBaseBindComm的ReadOnly属性State(创建连接的状态)

        'True(创建成功),False(创建失败)

        Private StateVal As Boolean

        Public ReadOnly Property State() As Boolean

            Get

                Return StateVal

            End Get

        End Property


    End Class


    Public Class OrganComm


        '//Defined Structure  PublicOrganIDStructure

        '//Structure descriptoin

        '//本结构存取 企业组织机构Id 

        '//顶层(DeptTopID)、一级(DeptMidId),二级ID(DeptLowId)        


        '//Begin define Structure PublicOrganIDStructure

        Public Structure PublicOrganIDStructure

            Public DeptTopID As String

            Public DeptMidId As String

            Public DeptLowId As String

        End Structure

        '//End define Structure PublicOrganIDStructure

     &nb

[1] [2] 下一页


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |