Public Class Cls_OpreateSQLDB Private bConnectFlag As Boolean = False '定义一个连接状态标志 ''################
Public var_Cnn As New SqlClient.SqlConnection '数据库连接,可以外部使用 ''################
Public ReadOnly Property pry_ConnectString() As String '数据库连接字串属性(只读)
Get
Return var_Cnn.ConnectionString
End Get
End Property ''################
Public ReadOnly Property pry_ConnectState() As Integer '数据库连接字串属性(只读)
Get
Return var_Cnn.State
End Get
End Property '################
Public Function Fun_ConnectionClose() As Boolean '关闭数据连接
Try
var_Cnn.Close()
Fun_ConnectionClose = True
Finally
Fun_ConnectionClose = False
End Try
End Function ''################
Public Overloads Function Fun_ExecuteSQL(ByVal strCmdString As String, ByRef objDataReader As SqlDataReader) As Boolean
'执行数据库查询命令,返回是否成功
Dim Obj_cmd As New SqlCommand '数据库命令,内部使用
Dim retDataReader As SqlDataReader '数据库记录集
Dim bSuccessFlag As Boolean = False If Not bConnectFlag Then
MsgBox("数据库还未连接,请先连接数据库", MsgBoxStyle.Critical, "编程用户系统信息")
Exit Function
End If
If Not var_Cnn.State = ConnectionState.Open Then
MsgBox("数据库连接已断开,请重新启动系统。", MsgBoxStyle.Information, "软件信息")
Exit Function
End If
Try
With Obj_cmd
.Connection = var_Cnn
.CommandType = CommandType.Text
.CommandText = strCmdString End With
retDataReader = Obj_cmd.ExecuteReader '执行一个有结果集的查询
bSuccessFlag = True
Catch e As Exception '处理错误信息
bSuccessFlag = False
MsgBox(e.ToString, MsgBoxStyle.Critical)
End Try
objDataReader = retDataReader '返回记录集
Return bSuccessFlag
End Function ''################
Public Overloads Function Fun_ExecuteSQL(ByVal strCmdString As String, ByRef iRecordCount As Integer) As Boolean
'执行数据库查询命令,返回是否成功
Dim Obj_cmd As New SqlCommand '数据库命令,内部使用
Dim bSuccessFlag As Boolean = False If Not bConnectFlag Then
MsgBox("数据库还未连接,请先连接数据库", MsgBoxStyle.Critical, "编程用户系统信息")
Exit Function
End If
If Not var_Cnn.State = ConnectionState.Open Then
MsgBox("数据库连接已断开,请重新启动系统。", MsgBoxStyle.Information, "软件信息")
Exit Function
End If
Try
With Obj_cmd
.Connection = var_Cnn
.CommandType = CommandType.Text
.CommandText = strCmdString
End With
iRecordCount = Obj_cmd.ExecuteNonQuery '执行一个无结果集的查询
bSuccessFlag = True
Catch e As Exception '处理错误信息
bSuccessFlag = False
MsgBox(e.ToString, MsgBoxStyle.Critical)
End Try
Return bSuccessFlag
End Function '图片:
Public Overloads Function Fun_ExecuteSQL(ByVal strCmdString As String, ByRef objDataReader As SqlDataReader, ByVal iCount As Integer, ByVal ParamArray Pic() As Object) As Boolean
'执行数据库表中有相关Image类型数据的重载函数
'Pic():分两组,每组的第一个参数是表中的要操作的Image字段的名称
' 第二个参数是Image字段的值(, 一般是Byet类型)
Dim Obj_cmd As New SqlCommand '数据库命令,内部使用
Dim retDataReader As SqlDataReader '数据库记录集
Dim bSuccessFlag As Boolean = False
Dim i As Int16 '传来参数数组的循环变量
Dim j As Int16 '参数列表的循环变量
Dim p(0) As SqlParameter '用于存储参数的参数列表数组
If Not bConnectFlag Then
MsgBox("数据库还未连接,请先连接数据库", MsgBoxStyle.Critical, "编程用户系统信息")
Exit Function
End If
If Not var_Cnn.State = ConnectionState.Open Then
MsgBox("数据库连接已断开,请重新启动系统。", MsgBoxStyle.Information, "软件信息")
Exit Function
End If
Try
With Obj_cmd
.Connection = var_Cnn
.CommandType = CommandType.Text
For i = 0 To Pic.Length - 1 Step 2 '循环传来参数一半的次数
ReDim p(p.Length) '重新定义参数列表
p(j) = New SqlParameter(CStr("@" & Pic(i)), SqlDbType.Image) '定一个Sql的Image类型参数
p(j).Value = Pic(i + 1) '给参数赋值
.Parameters.Add(p(j)) '添加到参数列表
j = j + 1 '参数列表循环+1
Next i
.CommandText = strCmdString
End With
retDataReader = Obj_cmd.ExecuteReader '执行一个有结果集的查询
objDataReader = retDataReader '执行一个无结果集的查询
bSuccessFlag = True
Catch e As Exception '处理错误信息
bSuccessFlag = False
MsgBox(e.ToString, MsgBoxStyle.Critical)
End Try
Return bSuccessFlag
End Function
Public var_Cnn As New SqlClient.SqlConnection '数据库连接,可以外部使用 ''################
Public ReadOnly Property pry_ConnectString() As String '数据库连接字串属性(只读)
Get
Return var_Cnn.ConnectionString
End Get
End Property ''################
Public ReadOnly Property pry_ConnectState() As Integer '数据库连接字串属性(只读)
Get
Return var_Cnn.State
End Get
End Property '################
Public Function Fun_ConnectionClose() As Boolean '关闭数据连接
Try
var_Cnn.Close()
Fun_ConnectionClose = True
Finally
Fun_ConnectionClose = False
End Try
End Function ''################
Public Overloads Function Fun_ExecuteSQL(ByVal strCmdString As String, ByRef objDataReader As SqlDataReader) As Boolean
'执行数据库查询命令,返回是否成功
Dim Obj_cmd As New SqlCommand '数据库命令,内部使用
Dim retDataReader As SqlDataReader '数据库记录集
Dim bSuccessFlag As Boolean = False If Not bConnectFlag Then
MsgBox("数据库还未连接,请先连接数据库", MsgBoxStyle.Critical, "编程用户系统信息")
Exit Function
End If
If Not var_Cnn.State = ConnectionState.Open Then
MsgBox("数据库连接已断开,请重新启动系统。", MsgBoxStyle.Information, "软件信息")
Exit Function
End If
Try
With Obj_cmd
.Connection = var_Cnn
.CommandType = CommandType.Text
.CommandText = strCmdString End With
retDataReader = Obj_cmd.ExecuteReader '执行一个有结果集的查询
bSuccessFlag = True
Catch e As Exception '处理错误信息
bSuccessFlag = False
MsgBox(e.ToString, MsgBoxStyle.Critical)
End Try
objDataReader = retDataReader '返回记录集
Return bSuccessFlag
End Function ''################
Public Overloads Function Fun_ExecuteSQL(ByVal strCmdString As String, ByRef iRecordCount As Integer) As Boolean
'执行数据库查询命令,返回是否成功
Dim Obj_cmd As New SqlCommand '数据库命令,内部使用
Dim bSuccessFlag As Boolean = False If Not bConnectFlag Then
MsgBox("数据库还未连接,请先连接数据库", MsgBoxStyle.Critical, "编程用户系统信息")
Exit Function
End If
If Not var_Cnn.State = ConnectionState.Open Then
MsgBox("数据库连接已断开,请重新启动系统。", MsgBoxStyle.Information, "软件信息")
Exit Function
End If
Try
With Obj_cmd
.Connection = var_Cnn
.CommandType = CommandType.Text
.CommandText = strCmdString
End With
iRecordCount = Obj_cmd.ExecuteNonQuery '执行一个无结果集的查询
bSuccessFlag = True
Catch e As Exception '处理错误信息
bSuccessFlag = False
MsgBox(e.ToString, MsgBoxStyle.Critical)
End Try
Return bSuccessFlag
End Function '图片:
Public Overloads Function Fun_ExecuteSQL(ByVal strCmdString As String, ByRef objDataReader As SqlDataReader, ByVal iCount As Integer, ByVal ParamArray Pic() As Object) As Boolean
'执行数据库表中有相关Image类型数据的重载函数
'Pic():分两组,每组的第一个参数是表中的要操作的Image字段的名称
' 第二个参数是Image字段的值(, 一般是Byet类型)
Dim Obj_cmd As New SqlCommand '数据库命令,内部使用
Dim retDataReader As SqlDataReader '数据库记录集
Dim bSuccessFlag As Boolean = False
Dim i As Int16 '传来参数数组的循环变量
Dim j As Int16 '参数列表的循环变量
Dim p(0) As SqlParameter '用于存储参数的参数列表数组
If Not bConnectFlag Then
MsgBox("数据库还未连接,请先连接数据库", MsgBoxStyle.Critical, "编程用户系统信息")
Exit Function
End If
If Not var_Cnn.State = ConnectionState.Open Then
MsgBox("数据库连接已断开,请重新启动系统。", MsgBoxStyle.Information, "软件信息")
Exit Function
End If
Try
With Obj_cmd
.Connection = var_Cnn
.CommandType = CommandType.Text
For i = 0 To Pic.Length - 1 Step 2 '循环传来参数一半的次数
ReDim p(p.Length) '重新定义参数列表
p(j) = New SqlParameter(CStr("@" & Pic(i)), SqlDbType.Image) '定一个Sql的Image类型参数
p(j).Value = Pic(i + 1) '给参数赋值
.Parameters.Add(p(j)) '添加到参数列表
j = j + 1 '参数列表循环+1
Next i
.CommandText = strCmdString
End With
retDataReader = Obj_cmd.ExecuteReader '执行一个有结果集的查询
objDataReader = retDataReader '执行一个无结果集的查询
bSuccessFlag = True
Catch e As Exception '处理错误信息
bSuccessFlag = False
MsgBox(e.ToString, MsgBoxStyle.Critical)
End Try
Return bSuccessFlag
End Function
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货