VB.NET如何实现通用SQL Server连接类?

您当前的位置:   首页 > 首页 > 解决方案
VB.NET如何实现通用SQL Server连接类?
发布时间:2026-07-03 09:27:35

*************************************************************************

'//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,

VB.NET如何实现通用SQL Server连接类?

'//Begin define Function LinkedSqlServer

Public Overloads Function LinkedSqlServer( _

VB.NET如何实现通用SQL Server连接类?

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

Public Class OrganComm

IDeptOrgid = Trim(IDeptOrgid)

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

VB.NET如何实现通用SQL Server连接类?


OrganID.DeptTopID = Microsoft.VisualBasic.Left(Orgid, 6)

VB.NET如何实现通用SQL Server连接类?

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

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