数据库开发033数据库通用模块之DBDataReader与DBDataTable

本文深入探讨数据库通用模块中的DBDataReader和DBDataTable组件,详细解析它们的使用方法和在数据库操作中的作用,帮助开发者更好地理解和应用这些组件进行数据处理。
摘要由CSDN通过智能技术生成

全部通用模块

Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.Odbc
'这个方法已经老了
Namespace DBConfig
    'Connection类-------------------------------------------------------
    Public Class DBConnection
        Private _strConn As String
        Public Property strConn As String
            Get
                Return _strConn
            End Get
            Set(ByVal value As String)
                _strConn = value
            End Set
        End Property
#If DB_OLEDB Then
        protected conn as oleDbConnection
#ElseIf DB_ODBC Then
        protected conn as OdbcConnecton
#Else
        Protected conn As SqlConnection
#End If
        Protected Sub open()
            If strConn Is Nothing Or strConn = "" Then
                MsgBox("请指定连接字符串")
                Return
            End If
#If DB_OLEDB Then
            conn=New oleDbConnection(strConn)
#ElseIf DB_ODBC Then
            conn=New OdbcConnection(strConn)
#Else
            conn = New SqlConnection(strConn)
#End If
            conn.Open()
        End Sub
        Protected Sub Close()
            conn.Close()
        End Sub
    End Class

    'Command类-----------------------------------------------------------------
    Public Class DBCommand
        Inherits DBConnection
        Public Sub New(ByVal str As String)
            strConn = str
        End Sub
        Public Function Insert(ByVal strSql As String) As Integer
            open()
#If DB_OLEDB Then
            dim cmd as OledbCommand=new OleDbCommand(strSql,conn)
#ElseIf DB_ODBC Then
             dim cmd as OdbcCommand=new odbcCommand(strSql,conn)
#Else
            Dim cmd As SqlCommand = New SqlCommand(strSql, conn)
#End If
            Dim count As Integer
            count = cmd.ExecuteNonQuery
            Close()
            Return count
        End Function

        Public Function Delete(ByVal table As String, ByVal row As String, ByVal value As String) As Integer
            open()
            Dim strSql As String = "Delete from " & table + "Where " & row & "=" & value
#If DB_OLEDB Then
             dim cmd as OledbCommand=new OleDbCommand(strSql,conn)
#ElseIf DB_ODBC Then
             dim cmd as ObdcCommand=new ObdcCommand(strSql,conn)
#Else
            Dim cmd As SqlCommand = New SqlCommand(strSql, conn)
#End If
            Dim count As Integer = 0
            count = cmd.ExecuteNonQuery
            Close()
            Return count
        End Function

        Public Function Update(ByVal table As String, ByVal strContent As String, ByVal row As String, ByVal value As Integer) As Integer
            open()
            Dim strSql As String = "Update " & table & " Set " & strContent & " Where " & row & "=" & value & ""
#If DB_OLEDB Then
           
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ngbshzhn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值