Tutorials to .com

Tutorials to .com » Database » Sqlserver » Public class Connect SQLSERVER

Public class Connect SQLSERVER

Print View , by: iSee ,Total views: 6 ,Word Count: 773 ,Date: Mon, 24 Aug 2009 Time: 4:07 AM

Public class Connect SQL SERVER
>************************************************* ************************************************** **
/ / 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 to access the database server name (Dbserver), database user ID (UserId),
/ / database user password (UserPWD), the database name (Dbase), for the database connection parameters.
/ / In order to meet the needs of some simple queries, providing expanded variable common table (DBTable),
/ / Query field name (QueryFieldName), query field values

/ / 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
************************************************** *********************
/ / ** Define to connect SQL Server Database universal functions ** / /
/ / This function creates a connection to the specified database connection object SqlConnection
/ / This function has one parameter, IPublicApplication for 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 ex As Exception
MsgBox (ex.ToString)
StateVal = False
LinkedSqlServer = Nothing
Exit Function
End Try
End Function


End defined LinkedSqlServer
************************************************** *********************

************************************************** *********************
/ / ** Define to connect SQL Server Database universal functions ** / /
/ / This function creates a connection to the specified database connection object SqlConnection
/ / This function has one parameter, IPublicApplication for 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 & _
"; 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
************************************************** *********************


Defined class DBaseBindComm the ReadOnly property of State (to create the connection state)
True (to create a successful), False (to create failure)
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
/ / The structure of access to corporate Organization Id
/ / Top (DeptTopID), 1 (DeptMidId), 2 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 to connect SQL Server Database universal functions ** / /
/ / This function creates a connection to the specified database connection object SqlConnection
/ / This function has one parameter, IPublicApplication for 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
************************************************** *************************************************


Microsoft SQL Server Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.