?? c_sqlhelper.vb
字號:
ByVal ParamArray commandParameters() As oledbParameter) As DataSet
If (connectionString Is Nothing OrElse connectionString.Length = 0) Then Throw New ArgumentNullException("connectionString")
' Create & open a oledbconnection, and dispose of it after we are done
Dim connection As oledbconnection = Nothing
Try
connection = New oledbconnection(connectionString)
connection.Open()
' Call the overload that takes a connection in place of the connection string
Return ExecuteDataset(connection, commandType, commandText, commandParameters)
Finally
If Not connection Is Nothing Then connection.Dispose()
End Try
End Function ' ExecuteDataset
' Execute a stored procedure via a oledbCommand (that returns a resultset) against the database specified in
' the connection string using the provided parameter values. This method will discover the parameters for the
' stored procedure, and assign the values based on parameter order.
' This method provides no access to output parameters or the stored procedure' s return value parameter.
' e.g.:
' Dim ds As Dataset= ExecuteDataset(connString, "GetOrders", 24, 36)
' Parameters:
' -connectionString - a valid connection string for a oledbconnection
' -spName - the name of the stored procedure
' -parameterValues - an array of objects to be assigned as the input values of the stored procedure
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal connectionString As String, _
ByVal spName As String, _
ByVal ParamArray parameterValues() As Object) As DataSet
If (connectionString Is Nothing OrElse connectionString.Length = 0) Then Throw New ArgumentNullException("connectionString")
If (spName Is Nothing OrElse spName.Length = 0) Then Throw New ArgumentNullException("spName")
Dim commandParameters As oledbParameter()
' If we receive parameter values, we need to figure out where they go
If Not (parameterValues Is Nothing) AndAlso parameterValues.Length > 0 Then
' Pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName)
' Assign the provided values to these parameters based on parameter order
AssignParameterValues(commandParameters, parameterValues)
' Call the overload that takes an array of oledbParameters
Return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters)
Else ' Otherwise we can just call the SP without params
Return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName)
End If
End Function ' ExecuteDataset
' Execute a oledbCommand (that returns a resultset and takes no parameters) against the provided oledbconnection.
' e.g.:
' Dim ds As Dataset = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders")
' Parameters:
' -connection - a valid oledbconnection
' -commandType - the CommandType (stored procedure, text, etc.)
' -commandText - the stored procedure name or T-SQL command
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal connection As oledbconnection, _
ByVal commandType As CommandType, _
ByVal commandText As String) As DataSet
' Pass through the call providing null for the set of oledbParameters
Return ExecuteDataset(connection, commandType, commandText, CType(Nothing, oledbParameter()))
End Function ' ExecuteDataset
' Execute a oledbCommand (that returns a resultset) against the specified oledbconnection
' using the provided parameters.
' e.g.:
' Dim ds As Dataset = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders", new oledbParameter("@prodid", 24))
' Parameters:
' -connection - a valid oledbconnection
' -commandType - the CommandType (stored procedure, text, etc.)
' -commandText - the stored procedure name or T-SQL command
' -commandParameters - an array of SqlParamters used to execute the command
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal connection As oledbconnection, _
ByVal commandType As CommandType, _
ByVal commandText As String, _
ByVal ParamArray commandParameters() As oledbParameter) As DataSet
If (connection Is Nothing) Then Throw New ArgumentNullException("connection")
' Create a command and prepare it for execution
Dim cmd As New oledbCommand
Dim ds As New DataSet
Dim dataAdatpter As oledbDataAdapter = Nothing
Dim mustCloseConnection As Boolean = False
PrepareCommand(cmd, connection, CType(Nothing, oledbTransaction), commandType, commandText, commandParameters, mustCloseConnection)
Try
' Create the DataAdapter & DataSet
dataAdatpter = New oledbDataAdapter(cmd)
' Fill the DataSet using default values for DataTable names, etc
dataAdatpter.Fill(ds)
' Detach the oledbParameters from the command object, so they can be used again
cmd.Parameters.Clear()
Finally
If (Not dataAdatpter Is Nothing) Then dataAdatpter.Dispose()
End Try
If (mustCloseConnection) Then connection.Close()
' Return the dataset
Return ds
End Function ' ExecuteDataset
' Execute a stored procedure via a oledbCommand (that returns a resultset) against the specified oledbconnection
' using the provided parameter values. This method will discover the parameters for the
' stored procedure, and assign the values based on parameter order.
' This method provides no access to output parameters or the stored procedure' s return value parameter.
' e.g.:
' Dim ds As Dataset = ExecuteDataset(conn, "GetOrders", 24, 36)
' Parameters:
' -connection - a valid oledbconnection
' -spName - the name of the stored procedure
' -parameterValues - an array of objects to be assigned as the input values of the stored procedure
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal connection As oledbconnection, _
ByVal spName As String, _
ByVal ParamArray parameterValues() As Object) As DataSet
If (connection Is Nothing) Then Throw New ArgumentNullException("connection")
If (spName Is Nothing OrElse spName.Length = 0) Then Throw New ArgumentNullException("spName")
Dim commandParameters As oledbParameter()
' If we receive parameter values, we need to figure out where they go
If Not (parameterValues Is Nothing) AndAlso parameterValues.Length > 0 Then
' Pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName)
' Assign the provided values to these parameters based on parameter order
AssignParameterValues(commandParameters, parameterValues)
' Call the overload that takes an array of oledbParameters
Return ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters)
Else ' Otherwise we can just call the SP without params
Return ExecuteDataset(connection, CommandType.StoredProcedure, spName)
End If
End Function ' ExecuteDataset
' Execute a oledbCommand (that returns a resultset and takes no parameters) against the provided oledbTransaction.
' e.g.:
' Dim ds As Dataset = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders")
' Parameters
' -transaction - a valid oledbTransaction
' -commandType - the CommandType (stored procedure, text, etc.)
' -commandText - the stored procedure name or T-SQL command
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal transaction As oledbTransaction, _
ByVal commandType As CommandType, _
ByVal commandText As String) As DataSet
' Pass through the call providing null for the set of oledbParameters
Return ExecuteDataset(transaction, commandType, commandText, CType(Nothing, oledbParameter()))
End Function ' ExecuteDataset
' Execute a oledbCommand (that returns a resultset) against the specified oledbTransaction
' using the provided parameters.
' e.g.:
' Dim ds As Dataset = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders", new oledbParameter("@prodid", 24))
' Parameters
' -transaction - a valid oledbTransaction
' -commandType - the CommandType (stored procedure, text, etc.)
' -commandText - the stored procedure name or T-SQL command
' -commandParameters - an array of SqlParamters used to execute the command
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal transaction As oledbTransaction, _
ByVal commandType As CommandType, _
ByVal commandText As String, _
ByVal ParamArray commandParameters() As oledbParameter) As DataSet
If (transaction Is Nothing) Then Throw New ArgumentNullException("transaction")
If Not (transaction Is Nothing) AndAlso (transaction.Connection Is Nothing) Then Throw New ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction")
' Create a command and prepare it for execution
Dim cmd As New oledbCommand
Dim ds As New DataSet
Dim dataAdatpter As oledbDataAdapter = Nothing
Dim mustCloseConnection As Boolean = False
PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, mustCloseConnection)
Try
' Create the DataAdapter & DataSet
dataAdatpter = New oledbDataAdapter(cmd)
' Fill the DataSet using default values for DataTable names, etc
dataAdatpter.Fill(ds)
' Detach the oledbParameters from the command object, so they can be used again
cmd.Parameters.Clear()
Finally
If (Not dataAdatpter Is Nothing) Then dataAdatpter.Dispose()
End Try
' Return the dataset
Return ds
End Function ' ExecuteDataset
' Execute a stored procedure via a oledbCommand (that returns a resultset) against the specified
' oledbTransaction using the provided parameter values. This method will discover the parameters for the
' stored procedure, and assign the values based on parameter order.
' This method provides no access to output parameters or the stored procedure' s return value parameter.
' e.g.:
' Dim ds As Dataset = ExecuteDataset(trans, "GetOrders", 24, 36)
' Parameters:
' -transaction - a valid oledbTransaction
' -spName - the name of the stored procedure
' -parameterValues - an array of objects to be assigned as the input values of the stored procedure
' Returns: A dataset containing the resultset generated by the command
Public Overloads Shared Function ExecuteDataset(ByVal transaction As oledbTransaction, _
ByVal spName As String, _
ByVal ParamArray parameterValues() As Object) As DataSet
If (transaction Is Nothing) Then Throw New ArgumentNullException("transaction")
If Not (transaction Is Nothing) AndAlso (transaction.Connection Is Nothing) Then Throw New ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction")
If (spName Is Nothing OrElse spName.Length = 0) Then Throw New ArgumentNullException("spName")
Dim commandParameters As oledbParameter()
' If we receive parameter values, we need to figure out where they go
If Not (parameterValues Is Nothing) AndAlso parameterValues.Length > 0 Then
' Pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName)
' Assign the provided values to these parameters based on parameter order
AssignParameterValues(commandParameters, parameterValues)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -