微软通用类库下载SQLHelper

 
微软企业图书馆是一家集可重复使用的应用软件开发人员专门设计来协助块与普通企业发展方面的挑战。这个版本包括:缓存块,加密块、数据存储块,异常处理块、测井块、策略注入块、安全块,确认街区,和统一。
 
 
数据访问层
 
 
使用例子:
using Microsoft.ApplicationBlocks.Data;
 
 List paramlist = new List();
           paramlist.Add(new SqlParameter("@isMonitor", isMonitorList));
           paramlist.Add(new SqlParameter("@status", status));
               
          
           return Convert.ToInt32( SqlHelper.ExecuteScalar((SqlConnection)conn,sql,paramlist.ToArray()) );
值得注意的是:在数据访问层中,传递参数顺序一定要和存储过程写的参数顺序一模一样,否则遇到类型不一样的情况会报错,编译不通过,不清楚为什么?下面的例子,如果1.6行顺序变的话,就出错了
或者  //   SqlParameter[] param =  {
            1 //  new SqlParameter("@usercode",user.userCode ),
            2 //  new SqlParameter("@userName", user.userName),
            3 //new SqlParameter("@password", user.Password),
             4//  new SqlParameter("@description", user.description),
            5 //  new SqlParameter("@actived", user.Actived),
             6//  new SqlParameter("@workgroupID", user.workgroupID)
             //  };
 
 
使用的实例子
private void cmdSample1_Click(object sender, System.EventArgs e)
  {
   // SqlDataReader that will hold the returned results  
   SqlDataReader dr = null;
   
   // SqlConnection that will be used to execute the sql commands
   SqlConnection connection = null;
   try
   {
    try
    {
     connection = GetConnection(txtConnectionString.Text);
    }
    catch
    {
     MessageBox.Show("The connection with the database can磘 be established", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     return;
    }
     
    
   }
   catch(Exception ex)
   {
   
   }
   finally
   {
    if(dr != null)
     ((IDisposable)dr).Dispose();
    if(connection != null)
     connection.Dispose();
   }
         
  } 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-687478/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23109131/viewspace-687478/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值