自己做项目的时候学着写的
Imports System.Data
Imports System.Data.sqlClient
Imports System.Data.sqlClient
''' -----------------------------------------------------------------------------
''' Project : ComClass
''' Class : sqlHelp
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' 数据访问抽象基础类
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public NotInheritable Class sqlHelp
Private Shared connectingstrings As String = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString.Trim
''' Project : ComClass
''' Class : sqlHelp
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' 数据访问抽象基础类
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public NotInheritable Class sqlHelp
Private Shared connectingstrings As String = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString.Trim
#Region "ExecNonsql执行sql语句,无返回"
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecNonsql
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <param name="sqlParms"></param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function ExecNonsql(ByVal sqlString As String)
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
Public Overloads Shared Function ExecNonsql(ByVal sqlString As String,ByVal cmdtype As CommandType,ByVal sqlParms As sqlParameter())
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,myConn,Nothing,cmdtype,sqlString,sqlParms)
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
#End Region
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecNonsql
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <param name="sqlParms"></param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function ExecNonsql(ByVal sqlString As String)
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
Public Overloads Shared Function ExecNonsql(ByVal sqlString As String,ByVal cmdtype As CommandType,ByVal sqlParms As sqlParameter())
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,myConn,Nothing,cmdtype,sqlString,sqlParms)
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
#End Region
#Region "ExecutesqlTran执行sql语句,实现数据库事务"
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecutesqlTran
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <param name="sqlnum">sql语句的行数(0或者正确的行数)</param>
''' <returns>true/false</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function ExecutesqlTran(ByVal sqlString As String,ByVal sqlnum As String)
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Dim myTrans As sqlTransaction
Dim errorStr As String
Dim reInt As String
Dim rebol As Boolean
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
myTrans = myConn.BeginTransaction
cmd.Transaction = myTrans
reInt = cmd.ExecuteNonQuery()
If sqlnum = 0 Then
myTrans.Commit()
rebol = True
Else
If reInt = sqlnum Then
myTrans.Commit()
rebol = True
Else
reInt = 0
myTrans.Rollback()
rebol = False
End If
End If
Catch ex As Exception
errorStr = ex.ToString
reInt = 0
myTrans.Rollback()
rebol = False
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
Return rebol
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecutesqlTran
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <param name="sqlnum">sql语句的行数(0或者正确的行数)</param>
''' <returns>true/false</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function ExecutesqlTran(ByVal sqlString As String,ByVal sqlnum As String)
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Dim myTrans As sqlTransaction
Dim errorStr As String
Dim reInt As String
Dim rebol As Boolean
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
myTrans = myConn.BeginTransaction
cmd.Transaction = myTrans
reInt = cmd.ExecuteNonQuery()
If sqlnum = 0 Then
myTrans.Commit()
rebol = True
Else
If reInt = sqlnum Then
myTrans.Commit()
rebol = True
Else
reInt = 0
myTrans.Rollback()
rebol = False
End If
End If
Catch ex As Exception
errorStr = ex.ToString
reInt = 0
myTrans.Rollback()
rebol = False
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
Return rebol
End Function
#End Region
#Region "Executesql// Executesql执行sql语句,返回影响的记录数"
''' -----------------------------------------------------------------------------
''' <summary>
''' Executesql// Executesql
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <returns>返回影响的记录数</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function Executesql(ByVal sqlString As String) As Int16
Dim i As Int16 = 0
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
i = cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
Return i
End Function
Public Overloads Shared Function Executesql(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As Int16
Dim r As Int16 = 0
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
'''cmd.CommandType = cmdtype
FillsqlCommand(cmd,sqlParms)
r = cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
Return r
''' -----------------------------------------------------------------------------
''' <summary>
''' Executesql// Executesql
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <returns>返回影响的记录数</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function Executesql(ByVal sqlString As String) As Int16
Dim i As Int16 = 0
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
i = cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
Return i
End Function
Public Overloads Shared Function Executesql(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As Int16
Dim r As Int16 = 0
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
'''cmd.CommandType = cmdtype
FillsqlCommand(cmd,sqlParms)
r = cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
Return r
End Function
#End Region
#End Region
#Region "ExecuteScalarsql // ExecuteScalarS 执行sql语句,返回查询结果"
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteScalarsql // ExecuteScalarS
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <returns>返回第一行第一列</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function ExecuteScalarsql(ByVal sqlString As String) As Object
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Dim obj As Object = Nothing
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
obj = cmd.ExecuteScalar()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
Public Shared Function ExecuteScalarS(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As Object
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Dim obj As Object = Nothing
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
obj = cmd.ExecuteScalar()
cmd.Parameters.Clear()
Return obj
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
#End Region
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteScalarsql // ExecuteScalarS
''' </summary>
''' <param name="sqlString">sql语句</param>
''' <returns>返回第一行第一列</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function ExecuteScalarsql(ByVal sqlString As String) As Object
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Dim obj As Object = Nothing
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
obj = cmd.ExecuteScalar()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
Public Shared Function ExecuteScalarS(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As Object
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Dim obj As Object = Nothing
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
obj = cmd.ExecuteScalar()
cmd.Parameters.Clear()
Return obj
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myConn.Dispose()
End Try
End Function
#End Region
#Region "ExecuteReader//ExecuteReadsql执行查询语句,返回sqlDataReader(使用该方法切记要手工关闭sqlDataReader和连接)"
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteReader//ExecuteReadsql
''' </summary>
''' <param name="sqlString">查询语句</param>
''' <returns>返回sqlDataReader</returns>
''' <remarks>
''' 使用该方法切记要手工关闭sqlDataReader和连接
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function ExecuteReader(ByVal sqlString As String) As sqlDataReader
Dim myReader As sqlDataReader = Nothing
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return myReader
Catch ex As Exception
Throw ex
End Try
End Function
Public Shared Function ExecuteReadsql(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As sqlDataReader
Dim myReader As sqlDataReader = Nothing
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
cmd.Parameters.Clear()
Return myReader
Catch ex As Exception
Throw ex
End Try
End Function
#End Region
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteReader//ExecuteReadsql
''' </summary>
''' <param name="sqlString">查询语句</param>
''' <returns>返回sqlDataReader</returns>
''' <remarks>
''' 使用该方法切记要手工关闭sqlDataReader和连接
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function ExecuteReader(ByVal sqlString As String) As sqlDataReader
Dim myReader As sqlDataReader = Nothing
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand(sqlString,myConn)
myConn.Open()
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return myReader
Catch ex As Exception
Throw ex
End Try
End Function
Public Shared Function ExecuteReadsql(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As sqlDataReader
Dim myReader As sqlDataReader = Nothing
Dim myConn As sqlConnection
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
cmd.Parameters.Clear()
Return myReader
Catch ex As Exception
Throw ex
End Try
End Function
#End Region
#Region "ExecuteDataSet // ExecuteDataSet执行查询语句,返回DataSet"
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteDataSet // ExecuteDataSet
''' </summary>
''' <param name="sqlString">查询语句</param>
''' <returns>返回DataSet</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function ExecuteDataSet(ByVal sqlString As String) As DataSet
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim ds As DataSet = Nothing
Try
myConn = New sqlConnection(connectingstrings)
myConn.Open()
myAdapter = New sqlDataAdapter(sqlString,myConn)
ds = New DataSet
myAdapter.Fill(ds,"ds")
Catch ex As Exception
Throw ex
Finally
myConn.Close()
myAdapter.Dispose()
myConn.Dispose()
End Try
Return ds
End Function
Public Overloads Shared Function ExecuteDataSet(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As DataSet
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim ds As DataSet = Nothing
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
myAdapter = New sqlDataAdapter(cmd)
ds = New DataSet
myAdapter.Fill(ds)
cmd.Parameters.Clear()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myAdapter.Dispose()
myConn.Dispose()
End Try
Return ds
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteDataSet // ExecuteDataSet
''' </summary>
''' <param name="sqlString">查询语句</param>
''' <returns>返回DataSet</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function ExecuteDataSet(ByVal sqlString As String) As DataSet
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim ds As DataSet = Nothing
Try
myConn = New sqlConnection(connectingstrings)
myConn.Open()
myAdapter = New sqlDataAdapter(sqlString,myConn)
ds = New DataSet
myAdapter.Fill(ds,"ds")
Catch ex As Exception
Throw ex
Finally
myConn.Close()
myAdapter.Dispose()
myConn.Dispose()
End Try
Return ds
End Function
Public Overloads Shared Function ExecuteDataSet(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As DataSet
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim ds As DataSet = Nothing
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
myAdapter = New sqlDataAdapter(cmd)
ds = New DataSet
myAdapter.Fill(ds)
cmd.Parameters.Clear()
Catch ex As Exception
Throw ex
Finally
myConn.Close()
cmd.Dispose()
myAdapter.Dispose()
myConn.Dispose()
End Try
Return ds
End Function
#End Region
#Region "ExecuteDataTablesql执行查询语句,返回DataTable"
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteDataTablesql
''' </summary>
''' <param name="sqlString">查询语句</param>
''' <returns>返回DataTable</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function ExecuteDataTablesql(ByVal sqlString As String) As DataTable
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim myTable As DataTable = Nothing
Try
myConn = New sqlConnection(connectingstrings)
myConn.Open()
myAdapter = New sqlDataAdapter(sqlString,myConn)
myAdapter.Fill(myTable)
Catch ex As Exception
Throw ex
Finally
myConn.Close()
myAdapter.Dispose()
myConn.Dispose()
End Try
Return myTable
End Function
Public Overloads Shared Function ExecuteDataTablesql(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As DataTable
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim myTable As DataTable = Nothing
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
myAdapter = New sqlDataAdapter(cmd)
myAdapter.Fill(myTable)
Catch ex As Exception
Throw ex
Finally
myConn.Close()
myAdapter.Dispose()
cmd.Dispose()
myConn.Dispose()
End Try
Return myTable
End Function
#End Region
''' -----------------------------------------------------------------------------
''' <summary>
''' ExecuteDataTablesql
''' </summary>
''' <param name="sqlString">查询语句</param>
''' <returns>返回DataTable</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Public Overloads Shared Function ExecuteDataTablesql(ByVal sqlString As String) As DataTable
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim myTable As DataTable = Nothing
Try
myConn = New sqlConnection(connectingstrings)
myConn.Open()
myAdapter = New sqlDataAdapter(sqlString,myConn)
myAdapter.Fill(myTable)
Catch ex As Exception
Throw ex
Finally
myConn.Close()
myAdapter.Dispose()
myConn.Dispose()
End Try
Return myTable
End Function
Public Overloads Shared Function ExecuteDataTablesql(ByVal sqlString As String,ByVal sqlParms As sqlParameter()) As DataTable
Dim myConn As sqlConnection
Dim myAdapter As sqlDataAdapter
Dim myTable As DataTable = Nothing
Dim cmd As sqlCommand
Try
myConn = New sqlConnection(connectingstrings)
cmd = New sqlCommand
FillsqlCommand(cmd,sqlParms)
myAdapter = New sqlDataAdapter(cmd)
myAdapter.Fill(myTable)
Catch ex As Exception
Throw ex
Finally
myConn.Close()
myAdapter.Dispose()
cmd.Dispose()
myConn.Dispose()
End Try
Return myTable
End Function
#End Region
#Region "填充sqlCommand,Private域"
''' -----------------------------------------------------------------------------
''' <summary>
''' FillsqlCommand
''' </summary>
''' <param name="cmd">sqlCommand</param>
''' <param name="conn">sqlConnection</param>
''' <param name="trans">sqlTransaction</param>
''' <param name="cmdType">CommandType</param>
''' <param name="cmdText">语句</param>
''' <param name="sqlParms">sqlParameter</param>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Private Shared Sub FillsqlCommand(ByVal cmd As sqlCommand,ByVal conn As sqlConnection,ByVal trans As sqlTransaction,ByVal cmdType As CommandType,ByVal cmdText As String,ByVal sqlParms As sqlParameter())
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
cmd.Connection = conn
cmd.CommandType = cmdType
cmd.CommandText = cmdText
If Not (trans Is Nothing) Then
cmd.Transaction = trans
End If
If Not (sqlParms Is Nothing) Then
For Each sqlParm As sqlParameter In sqlParms
If (sqlParm.Direction = ParameterDirection.Input Or sqlParm.Direction = ParameterDirection.InputOutput) And sqlParm.Value Is Nothing Then
sqlParm.Value = DBNull.Value
End If
cmd.Parameters.Add(sqlParm)
Next
End If
End Sub
#End Region
''' -----------------------------------------------------------------------------
''' <summary>
''' FillsqlCommand
''' </summary>
''' <param name="cmd">sqlCommand</param>
''' <param name="conn">sqlConnection</param>
''' <param name="trans">sqlTransaction</param>
''' <param name="cmdType">CommandType</param>
''' <param name="cmdText">语句</param>
''' <param name="sqlParms">sqlParameter</param>
''' <remarks>
''' </remarks>
''' <history>
''' [skyapplezhao]2009-4-23Created
''' </history>
''' -----------------------------------------------------------------------------
Private Shared Sub FillsqlCommand(ByVal cmd As sqlCommand,ByVal conn As sqlConnection,ByVal trans As sqlTransaction,ByVal cmdType As CommandType,ByVal cmdText As String,ByVal sqlParms As sqlParameter())
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
cmd.Connection = conn
cmd.CommandType = cmdType
cmd.CommandText = cmdText
If Not (trans Is Nothing) Then
cmd.Transaction = trans
End If
If Not (sqlParms Is Nothing) Then
For Each sqlParm As sqlParameter In sqlParms
If (sqlParm.Direction = ParameterDirection.Input Or sqlParm.Direction = ParameterDirection.InputOutput) And sqlParm.Value Is Nothing Then
sqlParm.Value = DBNull.Value
End If
cmd.Parameters.Add(sqlParm)
Next
End If
End Sub
#End Region
End Class