使用SqlHelper的一个小技巧(2)
''' <param name="commandParameters">an array of SqlParameters to be associated with the command or 'null' if no parameters are required</param>
Private Shared Sub PrepareCommand(ByVal command As SqlCommand, _
ByVal connection As SqlConnection, _
ByVal transaction As SqlTransaction, _
ByVal commandType As CommandType, _
ByVal commandText As String, _
ByVal commandParameters() As SqlParameter)
'if the provided connection is not open, we will open it
If connection.State <> ConnectionState.Open Then
connection.Open()
End If
'associate the connection with the command
command.Connection = connection
'set the command text (stored procedure name or SQL statement)
command.CommandText = commandText
'if we were provided a transaction, assign it.
If Not (transaction Is Nothing) Then
command.Transaction = transaction
End If
'set the command type
command.CommandType = commandType
'attach the command parameters if they are provided
If Not (commandParameters Is Nothing) Then
For Each p As SqlParameter In commandParameters
If (p.Direction <> ParameterDirection.Output) Then
Select Case p.DbType
Case DbType.String, DbType.StringFixedLength, DbType.AnsiString, DbType.AnsiStringFixedLength
相关新闻>>
- 发表评论
-
- 最新评论 更多>>