首页 > 开发 > 综合 > 正文

连接SQL SERVER公共类

2024-07-21 02:22:29
字体:
来源:转载
供稿:网友
'*****************************************************************************************************

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

'*************************************************************************************************** 
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表