Common classes to connect to SQL Server (turn)

Source: Internet
Author: User
Tags define exit dbase define function connect tostring trim
Server connects SQL Server's public class BLESTWQ (original)

'*****************************************************************************************************
'//Start date: May 27, 2002
'//End Date: May 27, 2002
'*****************************************************************************************************
Option Explicit on
' Option Strict on
'//***************************************************************************************************
Imports System.Data.SqlClient
'//***************************************************************************************************
'//begin defined Namespace
Namespace Sunerp.CommClass.Comm
'//defined Structure publicapplicationval
'//structure Descriptoin
'//This structure accesses the database server name (dbserver), the database user ID (UserId),
'//database user password (userpwd), database name (Dbase), which provides parameters for the joined database.
'//In order to meet the needs of some simple queries, the extended variables commonly used table names (dbtable) are provided,
'//query field name (queryfieldname), query field value
'//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
''***********************************************************************
'//** defines a common function to connect to SQL Server database **//
'//This function creates a connection object to the specified database SqlConnection
'//This function has 1 parameters, Ipublicapplication is a 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" & _
";p assword=" & "Erpsa" & _
";d atabase=" & "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
''***********************************************************************

''***********************************************************************
'//** defines a common function to connect to SQL Server database **//
'//This function creates a connection object to the specified database SqlConnection
'//This function has 1 parameters, Ipublicapplication is a public data structure 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 & _
";p assword=" & Ipublicapplication.userpwd & _
";d atabase=" & 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
''***********************************************************************


' Define the ReadOnly property state of the class Dbasebindcomm (create the status of the connection)
' True (creation succeeded), False (create 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 accesses enterprise Organization ID
'//Top level (DEPTTOPID), Level (Deptmidid), level two 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
'//***************************************************************************************************        ''******* ****************************************************************
'//** defines a common function to connect to SQL Server database **//
'//This function creates a connection object to the specified database SqlConnection
'//This function has 1 parameters, Ipublicapplication is a public data structure 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




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.