Connect the public class (VB.NET) of SQL Server

zhaozj2021-02-16  57

Option Explicit on

'Option Strict on

'// ******************************************************** *********************** Imports system.data.sqlclient

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

'// Begin Defined Namespace

Namespace sunerp.commclass.comm

'// defined structure publicApplicationVal

'// structure descriptoin

'// This structure Access the database server name (dbserver), database user ID (userid),

'// Database User Password (UserPwd), Database Name (DBASE), provides parameters for the join database.

'// In order to meet the needs of some simple queries, it provides an extended variable common table name (DBTABLE).

'// QueryfieldName, query field value

'// Begin Define Structure PublicApplicationVal

Public Structure PolicApplicationVal

'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

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

'' // ** Define Universal Functions for SQL Server Database ** //

'// This function creates a connection object to the specified database SQLConnection

'// This function has 1 parameters, ipublicapplication is public data structure 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 exception

'Msgbox (ex.totring)

Stateval = false

Linkedsqlserver = Nothing

EXIT FUNCTION

END TRY

END FUNCTION

'End Defined LinkedSqlServer

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

'' // ** Define Universal Functions for SQL Server Database ** //

'// This function creates a connection object to the specified database SQLConnection

'// This function has 1 parameters, ipublicapplication is public data structure publicApplicationVal,

'// begin define function linkedsqlserver

Public overloads function linkedsqlserver (_

BYVAL ipublicapplication as publicapplicationvalval_

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 exception

'Msgbox (ex.totring)

Stateval = false

Linkedsqlserver = Nothing

EXIT FUNCTION

END TRY

END FUNCTION

'End Defined LinkedSqlServer

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

'' Defining the ReadOnly property State of the class DBasebindcomm (Create a connection status)

'' True (Created), False (Creation Failed)

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

'// This structure Acquisition Enterprise Organization Id

'// top layer (DEPTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTMID), Second Level 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

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

'' // ** Define Universal Functions for SQL Server Database ** //

'// This function creates a connection object to the specified database SQLConnection

'// This function has 1 parameters, ipublicapplication is public data structure publicApplicationVal,

'// Begin Define Function iParSedeptorgID

Public Function iparsedeptorgid (Byval Ideptorgid As String) AS PUBLICONIDSTRUCTURE

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.deptmididiD = Microsoft.visualBasic.right (OrgID, 6)

Organid.deptlowid = Microsoft.VisualBasic.right (IdeptorgID, 6)

Iparsedeptorgid = OrganID

END FUNCTION

'// end define function iparsedeptorgid

END CLASS

End Namespace

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

转载请注明原文地址:https://www.9cbs.com/read-19005.html

New Post(0)