DataObject.vb
上传用户:wj57717022
上传日期:2014-12-16
资源大小:4093k
文件大小:32k
- Imports System.Data
- Imports System.Data.SqlClient
- Imports System.Data.SqlTypes
- Imports System.Xml
- Imports System.Collections
- Imports System.Diagnostics
- Namespace DataAccess
- Public Class DataObject
- Inherits System.ComponentModel.Component
- #Region " 组件设计器生成的代码 "
- Public Sub New(ByVal Container As System.ComponentModel.IContainer)
- MyClass.New()
- 'Windows.Forms 类撰写设计器支持所必需的
- Container.Add(Me)
- End Sub
- Public Sub New()
- MyBase.New()
- '该调用是组件设计器所必需的。
- InitializeComponent()
- privateModuleName = Me.GetType.ToString
- '在 InitializeComponent() 调用之后添加任何初始化
- End Sub
- '组件重写 dispose 以清理组件列表。
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- '组件设计器所必需的
- Private components As System.ComponentModel.IContainer
- '注意: 以下过程是组件设计器所必需的
- '可以使用组件设计器修改此过程。
- '不要使用代码编辑器修改它。
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- components = New System.ComponentModel.Container
- End Sub
- #End Region
- #Region "定义变量和对象"
- '定义ADO.Net对象
- Private privateConnection As SqlConnection
- Private privateCommand As SqlCommand
- Private privateDataReader As SqlDataReader
- Private privateXMLReader As XmlReader
- Private privateSQLDataAdapter As SqlDataAdapter
- Private privateDataSet As DataSet
- '定义调用存储过程的参数数组
- Private privateParameterList As ArrayList = New ArrayList
- '定义连接对象的变量
- Private privateConnectionString As String
- Private privateServer As String
- Private privateDatabase As String
- Private privateUserName As String
- Private privatePassword As String
- '定义名称,释放内存对象,错误处理对象变量
- Private privateModuleName As String
- Private privateDisposedBoolean As Boolean
- Private Const privateExceptionMessage As String = "数据应用错误。错误信息可能记录在事件日志中"
- '定义SQL数据类型
- Public Enum SQLDataType
- SQLString
- SQLChar
- SQLInteger
- SQLBit
- SQLDateTime
- SQLDecimal
- SQLMoney
- SQLImage
- End Enum
- #End Region
- #Region "DataObject 构造函数"
- Public Sub New(ByVal ConnectionString As String)
- MyBase.New()
- privateConnectionString = ConnectionString
- privateModuleName = Me.GetType.ToString
- End Sub
- '定义带参数的构造函数
- Public Sub New(ByVal Server As String, ByVal Database As String, ByVal UserName As String, ByVal Password As String)
- MyBase.New()
- privateConnectionString = "Server=" + Server + ";Database=" + Database + ";User ID=" + UserName + ";Password=" + Password + ";"
- privateModuleName = Me.GetType.ToString
- End Sub
- #End Region
- #Region "Public Properties"
- 'ConnectionString
- Public Property ConnectionString() As String
- Get
- Try
- Return privateConnection.ConnectionString
- Catch
- Return ""
- End Try
- End Get
- Set(ByVal Value As String)
- privateConnectionString = Value
- End Set
- End Property
- Public Property Server() As String
- Get
- Try
- Return privateUserName
- Catch
- Return ""
- End Try
- End Get
- Set(ByVal Value As String)
- privateUserName = Value
- End Set
- End Property
- Public Property Database() As String
- Get
- Try
- Return privateDatabase
- Catch
- Return ""
- End Try
- End Get
- Set(ByVal Value As String)
- privateDatabase = Value
- End Set
- End Property
- Public Property UserName() As String
- Get
- Try
- Return privateUserName
- Catch
- Return ""
- End Try
- End Get
- Set(ByVal Value As String)
- privateUserName = Value
- End Set
- End Property
- Public Property Password() As String
- Get
- Try
- Return privatePassword
- Catch
- Return ""
- End Try
- End Get
- Set(ByVal Value As String)
- privatePassword = Value
- End Set
- End Property
- #End Region
- #Region "DataObject 函数"
- #Region "RunSQLDataSet - 输入SQL语句返回DataSet"
- '返回DataSet
- 'sql:查询字符串
- Public Function runSQLDataSet(ByVal SQL As String, Optional ByVal TableName As String = Nothing) As DataSet
- 'SQL长度不得小于10个字节
- ValidateSQLStatement(SQL)
- Try
- '检测对象是否在内存中被释放掉
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "这个对象已经被释放掉,你不能调用它.")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SQL, privateConnection)
- privateDataSet = New DataSet
- privateSQLDataAdapter = New SqlDataAdapter(privateCommand)
- If TableName = Nothing Then
- privateSQLDataAdapter.Fill(privateDataSet)
- Else
- privateSQLDataAdapter.Fill(privateDataSet, TableName)
- End If
- Return privateDataSet
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- Finally
- privateConnection.Close()
- End Try
- End Function
-
- #End Region
- #Region "runSQLDataReader - 输入SQL语句,返回一个DataReader"
- '返回DataReader
- 'sql:查询字符串
- Public Function runSQLDataReader(ByVal SQL As String) As SqlDataReader
- ValidateSQLStatement(SQL)
- Try
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it.")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SQL, privateConnection)
- privateConnection.Open()
- privateDataReader = privateCommand.ExecuteReader
- Return privateDataReader
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- privateConnection.Close()
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- End Try
- End Function
- #End Region
- #Region "runSQL - 运行SQL语句,没有返回值。"
- 'sql:查询字符串
- Public Function runSQLXML(ByVal SQL As String)
- ValidateSQLStatement(SQL)
- Try
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it.")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SQL, privateConnection)
- privateConnection.Open()
- privateCommand.ExecuteNonQuery()
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- Finally
- privateXMLReader.Close()
- privateConnection.Close()
- End Try
- End Function
- Public Sub runSQL(ByVal SQL As String)
- ValidateSQLStatement(SQL)
- Try
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it.")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SQL, privateConnection)
- privateConnection.Open()
- privateCommand.ExecuteNonQuery()
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- Finally
- privateConnection.Close()
- End Try
- End Sub
- #End Region
- #Region "RunSPDataSet - SPName:不带参数的存储过程,TableName:表名,返回一个DataSet"
- '返回DataSet
- 'SPName:不带参数的存储过程
- 'TableName:表名
- Public Function runSPDataSet(ByVal SPName As String, Optional ByVal TableName As String = Nothing) As DataSet
- ValidateSPStatement(SPName)
- Dim privateUsedParameter As Parameter '定义一个 Parameter 型对象
- Dim privateParameter As SqlParameter '定义一个 SQLParameter 型变量
- '把 privateParameterList数组里的索引值赋值给usedEnumerator
- Dim usedEnumerator As IEnumerator = privateParameterList.GetEnumerator()
- Try
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- Dim privateDataSet As New DataSet
- privateCommand = New SqlCommand(SPName, privateConnection)
- privateCommand.CommandType = CommandType.StoredProcedure
- '通过enumerator在privateParameterList数组里 获得 Parameter
- Do While (usedEnumerator.MoveNext())
- privateUsedParameter = Nothing
- '从 privateParameterList 数组里得到Parameter,赋值给privateUsedParameter
- privateUsedParameter = usedEnumerator.Current
- '转化为 SQLParameter 对象
- privateParameter = ConvertParameters(privateUsedParameter)
- '把privateParameter对象,加入到privateCommand对象的参数列表中
- privateCommand.Parameters.Add(privateParameter)
- Loop
- privateSQLDataAdapter = New SqlDataAdapter(privateCommand)
- '没有表名
- If TableName = Nothing Then
- privateSQLDataAdapter.Fill(privateDataSet)
- Else
- '有表名
- privateSQLDataAdapter.Fill(privateDataSet, TableName)
- End If
- Return privateDataSet
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- Finally
- privateConnection.Close()
- End Try
- End Function
- #End Region
- #Region "RunSPDataReader - 带参数的存储过程,返回一个DataReader"
- 'SPName:带参数的存储过程
- Public Function runSPDataReader(ByVal SPName As String) As SqlDataReader
- ValidateSPStatement(SPName)
- '设置Parameter对象
- Dim privateUsedParameter As Parameter '在privateParameterList数组里返回一个Parameter
- Dim privateParameter As SqlParameter
- Dim usedEnumerator As IEnumerator = privateParameterList.GetEnumerator()
- Try
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SPName, privateConnection)
- privateCommand.CommandType = CommandType.StoredProcedure
- Do While (usedEnumerator.MoveNext())
- privateUsedParameter = Nothing
- privateUsedParameter = usedEnumerator.Current
- privateParameter = ConvertParameters(privateUsedParameter)
- privateCommand.Parameters.Add(privateParameter)
- Loop
- privateConnection.Open()
- privateDataReader = privateCommand.ExecuteReader
- Return privateDataReader
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- privateConnection.Close()
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- End Try
- End Function
- #End Region
- #Region "runSPXMLReader - 返回SQLXML字符串"
- '返回privateXMLString字符串
- 'SPName:带参数的存储过程
- Public Function runSPXMLReader(ByVal SPName As String) As String
- ValidateSPStatement(SPName)
- Dim privateUsedParameter As Parameter
- Dim privateParameter As SqlParameter
- Dim usedEnumerator As IEnumerator = privateParameterList.GetEnumerator()
- Dim privateXMLString As String
- Try
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SPName, privateConnection)
- privateCommand.CommandType = CommandType.StoredProcedure
- Do While (usedEnumerator.MoveNext())
- privateUsedParameter = Nothing
- privateUsedParameter = usedEnumerator.Current
- privateParameter = ConvertParameters(privateUsedParameter)
- privateCommand.Parameters.Add(privateParameter)
- Loop
- privateConnection.Open()
- privateXMLReader = privateCommand.ExecuteXmlReader
- Do Until privateXMLReader.Read = False
- privateXMLString += privateXMLReader.ReadOuterXml & "<BR>"
- Loop
- Return privateXMLString
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- Finally
- privateXMLReader.Close()
- privateConnection.Close()
- End Try
- End Function
- #End Region
- #Region "runSPOutput - 带参数的存储过程返回ArrayList数组对象"
- Public Function runSPOutput(ByVal SPName As String) As ArrayList
- ValidateSPStatement(SPName)
- Dim privateUsedParameter As Parameter
- Dim privateParameter As SqlParameter
- Dim usedEnumerator As IEnumerator = privateParameterList.GetEnumerator()
- Dim outputParameters As New ArrayList
- Dim privateParameterOut As SqlParameter
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "This object has already been disposed. You cannot reuse it")
- End If
- privateConnection = New SqlConnection(privateConnectionString)
- privateCommand = New SqlCommand(SPName, privateConnection)
- privateCommand.CommandType = CommandType.StoredProcedure
- Do While (usedEnumerator.MoveNext())
- privateUsedParameter = Nothing
- privateUsedParameter = usedEnumerator.Current
- privateParameter = ConvertParameters(privateUsedParameter)
- privateCommand.Parameters.Add(privateParameter)
- Loop
- privateConnection.Open()
- privateCommand.ExecuteNonQuery()
- '通过循环取出存储过程的输出参数,赋给outputParameters数组对象
- For Each privateParameterOut In privateCommand.Parameters
- If privateParameterOut.Direction = ParameterDirection.Output Or privateParameterOut.Direction = ParameterDirection.ReturnValue Then
- '存储过程返回输出参数,赋值给outputParameters数组对象
- outputParameters.Add(privateParameterOut.Value)
- End If
- Next
- '返回数组
- Return outputParameters
- privateConnection.Close()
- End Function
- #End Region
- #End Region
- #Region "更新数据库"
- Public Function updatedataset(ByVal str As String, ByVal tablename As String, ByVal dsupdate As DataSet, ByVal rowstate As DataRowState) As Boolean
- Dim susses As New Boolean
- privateConnection = New SqlConnection(privateConnectionString)
- Try
- '检测对象是否在内存中被释放掉
- If privateDisposedBoolean = True Then
- Throw New ObjectDisposedException(privateModuleName, "这个对象已经被释放掉,你不能调用它.")
- End If
- privateCommand = New SqlCommand(str, privateConnection)
- privateSQLDataAdapter = New SqlDataAdapter(privateCommand)
- Dim dschange As DataSet
- If dsupdate.HasChanges(DataRowState.Added) Then
- dschange = dsupdate.GetChanges(DataRowState.Added)
- If dschange.HasErrors() Then
- dsupdate.RejectChanges()
- susses = False
- Else
- Dim scb As SqlCommandBuilder = New SqlCommandBuilder(privateSQLDataAdapter)
- privateSQLDataAdapter.Update(dschange, tablename)
- dsupdate.AcceptChanges()
- susses = True
- End If
- End If
- If dsupdate.HasChanges(DataRowState.Modified) Then
- dschange = dsupdate.GetChanges(DataRowState.Modified)
- If dschange.HasErrors() Then
- dsupdate.RejectChanges()
- susses = False
- Else
- Dim scb As SqlCommandBuilder = New SqlCommandBuilder(privateSQLDataAdapter)
- privateSQLDataAdapter.Update(dschange, tablename)
- dsupdate.AcceptChanges()
- susses = True
- End If
- End If
- If dsupdate.HasChanges(DataRowState.Deleted) Then
- dschange = dsupdate.GetChanges(DataRowState.Deleted)
- If dschange.HasErrors() Then
- dsupdate.RejectChanges()
- susses = False
- Else
- Dim scb As SqlCommandBuilder = New SqlCommandBuilder(privateSQLDataAdapter)
- privateSQLDataAdapter.Update(dschange, tablename)
- dsupdate.AcceptChanges()
- susses = True
- End If
- End If
- Return susses
- Catch ExceptionObject As Exception
- LogException(ExceptionObject)
- Throw New Exception(privateExceptionMessage, ExceptionObject)
- Finally
- privateConnection.Close()
- End Try
- End Function
- #End Region
- #Region "参数处理方法"
- Public Sub AddParameter(ByVal ParameterName As String, _
- Optional ByVal Value As Object = Nothing, _
- Optional ByVal SQLType As SQLDataType = Nothing, _
- Optional ByVal Size As Integer = Nothing, _
- Optional ByVal Direction As ParameterDirection = ParameterDirection.Input)
- Dim buildDataType As SqlDbType
- Dim buildParameter As Parameter = Nothing
- Select Case SQLType
- Case SQLDataType.SQLString
- buildDataType = SqlDbType.VarChar
- Case SQLDataType.SQLChar
- buildDataType = SqlDbType.Char
- Case SQLDataType.SQLInteger
- buildDataType = SqlDbType.Int
- Case SQLDataType.SQLBit
- buildDataType = SqlDbType.Bit
- Case SQLDataType.SQLDateTime
- buildDataType = SqlDbType.DateTime
- Case SQLDataType.SQLDecimal
- buildDataType = SqlDbType.Decimal
- Case SQLDataType.SQLMoney
- buildDataType = SqlDbType.Money
- Case SQLDataType.SQLImage
- buildDataType = SqlDbType.Image
- End Select
- buildParameter = New Parameter(ParameterName, Value, buildDataType, Size, Direction)
- privateParameterList.Add(buildParameter)
- End Sub
- '参数类
- Public Class Parameter
- Public ParameterName As String
- Public ParameterValue As Object
- Public ParameterDataType As SQLDataType
- Public ParameterSize As Integer
- Public ParameterDirectionUsed As ParameterDirection
- Sub New(ByVal passedParameterName As String, _
- Optional ByVal passedValue As Object = Nothing, _
- Optional ByVal passedSQLType As SQLDataType = Nothing, _
- Optional ByVal passedSize As Integer = Nothing, _
- Optional ByVal passedDirection As ParameterDirection = ParameterDirection.Input)
- ParameterName = passedParameterName
- ParameterValue = passedValue
- ParameterDataType = passedSQLType
- ParameterSize = passedSize
- ParameterDirectionUsed = passedDirection
- End Sub
- End Class
- '转化参数函数
- Private Function ConvertParameters(ByVal passedParameter As Parameter) As SqlParameter
- Dim returnSQLParameter As SqlParameter = New SqlParameter
- returnSQLParameter.ParameterName = passedParameter.ParameterName
- returnSQLParameter.Value = passedParameter.ParameterValue
- returnSQLParameter.SqlDbType = passedParameter.ParameterDataType
- returnSQLParameter.Size = passedParameter.ParameterSize
- returnSQLParameter.Direction = passedParameter.ParameterDirectionUsed
- Return returnSQLParameter
- End Function
- '清除privateParameterList数组
- Public Sub ClearParameters()
- Try
- privateParameterList.Clear()
- Catch parameterException As Exception
- Throw New Exception(privateExceptionMessage & " Parameter List did not clear", parameterException)
- End Try
- End Sub
- #End Region
- #Region "异常事件,并写入事件日志!"
- Private Sub LogException(ByRef ExceptionObject As Exception)
- Dim EventLogMessage As String
- Try
- EventLogMessage = "An error occured in the following module: " & privateModuleName & _
- " The Source was: " & ExceptionObject.Source & vbCrLf & _
- " With the Message: " & ExceptionObject.Message & vbCrLf & _
- " Stack Tace: " & ExceptionObject.StackTrace & vbCrLf & _
- " Target Site: " & ExceptionObject.TargetSite.ToString
- Dim localEventLog As New EventLog("Application")
- localEventLog.WriteEntry(privateModuleName, EventLogMessage, EventLogEntryType.Error, 55)
- Catch EventLogException As Exception
- Throw New Exception(privateExceptionMessage & " - EventLog Error: " & EventLogException.Message, EventLogException)
- End Try
- End Sub
- #End Region
- #Region "减测字符串长度"
- Private Sub ValidateSQLStatement(ByRef SQLStatement As String)
- 'SQL 语句不小于10个字节 ( "Select * form x" )
- If Len(SQLStatement) < 10 Then
- Throw New Exception(privateExceptionMessage & " The SQL Statement must be provided and at least 10 characters long")
- End If
- End Sub
- Private Sub ValidateSPStatement(ByRef SQLStatement As String)
- '存储过程 名称不小于10个字节 ( "Select * form x" )
- If Len(SQLStatement) < 2 Then
- Throw New Exception(privateExceptionMessage & " The Stored Procedure must be provided and at least 2 characters long")
- End If
- End Sub
- #End Region
- #Region "释放资源"
- Public Overloads Sub Dispose()
- If privateDisposedBoolean = False Then
- Try
- privateConnection.Dispose()
- Catch
- Finally
- MyBase.Dispose()
- GC.SuppressFinalize(Me)
- privateDisposedBoolean = True
- End Try
- End If
- End Sub
- #End Region
- #Region "返回发生变化的记录集"
- '返回发生变化的记录集.
- Public Sub returndatachange(ByVal returndataset As Data.DataSet)
- ' Dim datachange As Data.DataSet
- Dim dtable As Data.DataTable
- Dim drow As Data.DataRow
- Dim dcolumn As Data.DataColumn
- Try
- '更新数据-新增
- If returndataset.HasChanges(Data.DataRowState.Added) Then
- privateDataSet = returndataset.GetChanges(Data.DataRowState.Added)
- privateSQLDataAdapter.Update(privateDataSet)
- privateDataSet.AcceptChanges()
- 'Return datachange
- End If
- '更新数据-修改
- If returndataset.HasChanges(Data.DataRowState.Modified) Then
- privateDataSet = returndataset.GetChanges(Data.DataRowState.Modified)
- privateSQLDataAdapter.Update(privateDataSet)
- privateDataSet.AcceptChanges()
- 'Return datachange
- End If
- '更新数据-删除
- If returndataset.HasChanges(Data.DataRowState.Deleted) Then
- privateDataSet = returndataset.GetChanges(Data.DataRowState.Deleted)
- privateSQLDataAdapter.Update(privateDataSet)
- privateDataSet.AcceptChanges()
- 'Return datachange
- End If
- Catch Exceptionobject As Exception
- 'DataSet是否有错误
- If returndataset.HasErrors Then
- '遍历每一个表
- For Each dtable In returndataset.Tables
- 'Datatable是否有错误
- If dtable.HasErrors Then
- '遍历每一行
- For Each drow In dtable.Rows
- 'DataRow是否有错误
- If drow.HasErrors Then
- 'MessageBox.Show("记录:", drow.RowError)
- '遍历每一字段,找出DataColumn是否有错误
- For Each dcolumn In drow.GetColumnsInError
- ' MessageBox.Show(dcolumn.ColumnName)
- Next
- '清除行错误
- drow.ClearErrors()
- '取消发生错误的DataRow的更新.
- drow.RejectChanges()
- End If
- Next
- End If
- Next
- End If
- End Try
- End Sub
- #End Region
- #Region "属性数据库类"
- '功能:按SQL语句读取记录集
- '函数:SetDataSetFill
- '参数:String型strSQL----要选取记录集的SQL语句
- '返回:Boolean型 True--成功 False--失败
- '说明:如果数据集读取成功,则将记录集存储于myDataSet中
- '
- Public Overridable Function SetDataSetFill(ByVal p_strSQL As String) As Boolean
- Try
- If Not privateSQLDataAdapter Is Nothing Then privateSQLDataAdapter = Nothing
- privateSQLDataAdapter = New SqlDataAdapter(p_strSQL, privateConnection)
- MyClass.privateDataSet.Tables.Clear()
- privateSQLDataAdapter.Fill(privateDataSet)
- Catch ex As SqlException
- Return False
- End Try
- Return True
- End Function
- '功能:取得记录行数
- '函数:GetRecordCount
- '参数:无
- '返回:Integer 记录数目
- '说明:在调用此方法前,应先调用SetDataSetFill
- '
- Public Overloads Function GetRecordCount() As Integer
- Return MyClass.privateDataSet.Tables(0).Rows.Count()
- End Function
- '
- '功能:取得记录行数
- '函数:GetRecordCount
- '参数:String型strSQL语句
- '返回:Integer 记录数目
- '说明:在调用此方法前,不需要先调用SetDataSetFill,此函数直接将参数传给SetDataSetFill
- '
- Public Overloads Function GetRecordCount(ByVal strSql As String) As Integer
- If MyClass.SetDataSetFill(strSql) Then
- Return MyClass.GetRecordCount()
- Else
- Return 0
- End If
- End Function
- '
- '功能:取得字段数目
- '函数:GetFieldCount
- '参数:无
- '返回:Integer 字段数目
- '说明:在调用此方法前,要先调用SetDataSetFill
- '
- Public Overridable Function GetFieldCount() As Integer
- Return MyClass.privateDataSet.Tables(0).Columns.Count()
- End Function
- '
- '功能:取得字段数目
- '函数:GetFieldCount
- '参数:String型StrSQL
- '返回:Integer 字段数目
- '说明:在调用此方法前,不需要先调用SetDataSetFill,此函数直接将参数传给SetDataSetFill
- '
- Public Overridable Function GetFieldCount(ByVal strSQL As String) As Integer
- MyClass.SetDataSetFill(strSQL)
- Return MyClass.privateDataSet.Tables(0).Columns.Count()
- End Function
- '
- '功能:取得单元格数据库
- '参数:Short r--第r行 , short c---第几列
- '返回:String型单元数据
- '说明:在调用此方法前,要先调用SetDataSetFill
- Public Overridable Function GetTabValue(ByVal r As Short, ByVal c As Short) As String
- Return Convert.ToString(MyClass.privateDataSet.Tables(0).Rows(r)(c))
- End Function
- '
- '功能:取得单元格数据库
- '参数:string strSqL--SQL语句,Short r--第r行 , short c---第几列
- '返回:String型单元数据
- '说明:在调用此方法前,不要先调用SetDataSetFill
- Public Overridable Function GetTabValue(ByVal strSqL As String, ByVal r As Short, ByVal c As Short) As String
- MyClass.SetDataSetFill(strSqL)
- On Error GoTo Err
- Return MyClass.privateDataSet.Tables(0).Rows(r)(c)
- Err:
- Return ""
- End Function
- #End Region
- End Class
- End Namespace