- '数据库语句通用模块,代码来自紫外工控网http://bbs.ziwai.net
- Imports System.Data.Odbc
- Imports System.Data.OleDb
- Imports System.Data.SqlClient
- Namespace DBConfig
- Public Class DBCommand
- Inherits DBConnection
- '在构造函数中指定连接信息字符串
- Public Sub New(ByVal str As String)
- connstr = str
- End Sub
- Public Function insert(ByVal strSQL As String) As Integer
- '连接数据库
- Open()
- '创建SQlcommand实例
- #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
- 'count表示受影响的行数,初始化为0
- Dim count As Integer = 0
- '执行sql命令
- 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()
- '创建sql指令
- Dim strSQL As String = "delect from " + table + " where " + row + "=" + value
- #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
- 'count表示受影响的行数,初始化为0
- Dim count As Integer = 0
- '执行sql命令
- 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 String) As Integer
- '连接数据库
- Open()
- '创建sql指令
- Dim strSQL As String = "Update " + table + " set " + strContent + " where " + row + "=" + value
- #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
- 'count表示受影响的行数,初始化为0
- Dim count As Integer = 0
- '执行sql命令
- count = cmd.ExecuteNonQuery()
- '关闭数据库
- Close()
- Return count
- End Function
- End Class
- End Namespace
复制代码 |