网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 交易代码 > ASP.Net精品代码 > 正文

数据库操作通类实现

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

  Imports System

  Imports System.Data

  Imports System.Data.Common

  Imports System.Data.OleDb

  'Imports System.Data.SqlClient

  'Imports System.Data.Odbc

  'Imports Microsoft.Data.Odbc

  Imports System.Configuration

  Imports System.Reflection

  Public Class COpDB

  '连接字符串属性

  Private _ConnectString As String

  Public Property MyConnectString() As String

  Get

  Return _ConnectString

  End Get

  Set(ByVal Value As String)

  _ConnectString = Value

  End Set

  End Property

  '构造函数

  Public Sub New(ByVal connString As String)

  Me._ConnectString = connString

  End Sub

  '创建Connection

  Private Function GetConnection() As IDbConnection

  'Return New System.Data.SqlClient.SqlConnection(_ConnectString)

  Return New System.Data.OleDb.OleDbConnection(_ConnectString)

  End Function

  '创建Command

  Private Function GetCommand() As IDbCommand

  'Return New System.Data.SqlClient.SqlCommand

  Return New System.Data.OleDb.OleDbCommand

  End Function

  '

  Private Function GetCommand(ByVal Sql As String, ByVal iConn As IDbConnection) As IDbCommand

  'Return New System.Data.SqlClient.SqlCommand(Sql, iConn)

  Return New System.Data.OleDb.OleDbCommand(Sql, iConn)

  End Function

  '创建Adapater

  Private Function GetAdapater() As IDataAdapter

  'Return New System.Data.SqlClient.SqlDataAdapter

  Return New System.Data.OleDb.OleDbDataAdapter

  End Function

  Private Function GetAdapater(ByVal Sql As String, ByVal iConn As IDbConnection) As IDataAdapter

  'Return New System.Data.SqlClient.SqlDataAdapter(Sql, iConn)

  Return New System.Data.OleDb.OleDbDataAdapter(Sql, iConn)

  End Function

  Private Function GetAdapater(ByVal iCmd As IDbCommand) As IDataAdapter

  'Return New System.Data.SqlClient.SqlDataAdapter(iCmd)

  Return New System.Data.OleDb.OleDbDataAdapter(iCmd)

  End Function

  '多方式

  'Private Function GetDataAdapter(ByVal connType As String, ByVal sql As String) As IDbDataAdapter

  '    Select Case connType

  '        Case "OLE"

  '            idbAdapter = New OleDbDataAdapter(sql, Me._ConnectString)

  '        Case "SQL"

  '            idbAdapter = New SqlDataAdapter(sql, Me._ConnectString)

  '        Case "ODBC"

  '            idbAdapter = New OdbcDataAdapter(sql, Me._ConnectString)

  '        Case Else

  '            '

  '    End Select

  '    Return idbAdapter

  'End Function

  '返回执行有效行数

  Public Function ExecuteQuery(ByVal sqlString As String) As DataSet

  Dim iConn As System.Data.IDbConnection = Me.GetConnection()

  Dim ds As DataSet = New DataSet

  Try

  Dim iAdapter As System.Data.IDbDataAdapter = Me.GetAdapater(sqlString, iConn)

  'If iConn.State <> ConnectionState.Open Then

  '    iConn.Open()

  'End If

  iAdapter.Fill(ds)

  Catch ex As Exception

  Throw New Exception(ex.Message)

  Finally

  If iConn.State <> ConnectionState.Closed Then

  iConn.Close()

  End If

  End Try

  Return ds

  End Function

  Public Function ExecuteQuery(ByVal sqlString As String, ByVal iTableId As Integer) As DataTable

  Dim iConn As System.Data.IDbConnection = Me.GetConnection()

  Dim ds As DataSet = New DataSet

  Try

  Dim iAdapter As System.Data.IDbDataAdapter = Me.GetAdapater(sqlString, iConn)

  'If iConn.State <> ConnectionState.Open Then

  '    iConn.Open()

  'End If

  iAd

  • 上一篇资讯: ftp操作实现类
  • 下一篇资讯: ListView表头排序实现
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师