使用SqlHelper的一个小技巧(2)

来源:未知 责任编辑:责任编辑 发表时间:2014-03-23 22:29 点击:

''' <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

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • C#高级编程:数据库连接[1]
  • asp.net 设置GridView的选中行的实现代码
  • 经典C++程序1
  • IIS 自动回收导致后台定时器失效的问题解决
  • ASP.NET&#160;GridView列表代码示例
  • 微软ASP.NET站点部署指南(3):使用Web.Config文件的Transforma
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1