注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
危险无处不在 TCP连接暗藏杀机 查
简单三步走堵死SQLServer注入漏洞
黑客攻破SQL服务器系统的十种方法
解决IE强迫连接某网站的办法
限制单个IP并发TCP连接的iptable
透明防火墙架设的完全攻略(brid
linux定时备份mysql数据库
FTP连接后为什么列表错误,无法列
qmail+vpopmail+sqwebmail的安装
qmail Vpopmail And sqwebmail H
您现在的位置: 顶尖设计 >> IT学院 >> 数据库 >> MS SQL >> 文章正文
连接SQL SERVER的公共类(VB.NET)
作者:佚名  来源:不详  点击:  更新:2006-12-20
简介:
 

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

         &

[1] [2] 下一页




  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务