全部通用模块
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