串連SQL SERVER的公用類(轉)

來源:互聯網
上載者:User
server 串連SQL SERVER的公用類    blestwq(原作)  
  
'*****************************************************************************************************
'//開始日期: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
        '//***************************************************************************************************        ''***********************************************************************
        ''//**定義串連SQL Server Database的通用函數**//
        '//本函數建立一個到指定資料庫的連線物件 SqlConnection
        '//本函數有1個參數,IPublicApplication 為公用資料結構 PublicApplicationVal,

        '//Begin define Function IParseDeptOrgid
        Public Function IParseDeptOrgid(ByVal IDeptOrgid As String) As PublicOrganIDStructure
            Dim OrganID As New PublicOrganIDStructure()
            Dim Orgid As String

            IDeptOrgid = Trim(IDeptOrgid)
            Orgid = Microsoft.VisualBasic.Left(Trim(IDeptOrgid), 12)

            OrganID.DeptTopID = Microsoft.VisualBasic.Left(Orgid, 6)
            OrganID.DeptMidId = Microsoft.VisualBasic.Right(Orgid, 6)
            OrganID.DeptLowId = Microsoft.VisualBasic.Right(IDeptOrgid, 6)

            IParseDeptOrgid = OrganID
        End Function
        '//End define Function IParseDeptOrgid

    End Class


End Namespace




相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。