论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Asp.net教程
Tag:静态页面,treeview,gridview,repeater,dataset,sqldatareader,ado.net,上传,三层,ajax,xml,留言本,新闻发布,商城,注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,触发器,socket,form认证,登录,视频教程

连接SQL SERVER的公共类(VB.NET)

文章类别:Asp.net | 发表日期:2008-10-5 21:53:43

*************************************************************************
'//开始日期: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

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

上一篇:{应用}亲密接触ADO.NETv2.0 人气:3934
下一篇:{应用}将Session值储存于SQL Server中 人气:3796
视频教程列表
文章教程搜索
 
Asp.net推荐教程
Asp.net热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058