NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)

本文介绍了一个通用的数据访问层设计,支持多种数据库类型包括 SQL Server、Oracle 和 Access,并提供了丰富的数据操作方法,如执行SQL语句、存储过程调用等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


using  System;
using  System.Collections;
using  System.Collections.Specialized;
using  System.Data;
using  System.Data.SqlClient;
using  System.Data.OleDb;
using  System.Data.OracleClient;
using  System.Configuration;
using  System.Reflection;

namespace  SystemFramework.DAL
ExpandedBlockStart.gifContractedBlock.gif
{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
    
/// All rights reserved
    
/// 数据访问基础类
    
/// 用户可以修改满足自己项目的需要。
    
/// </summary>

    public class DataBaseLayer 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//数据库连接字符串(web.config来配置)
        
//<add key="ConnectionString" value="server=127.0.0.1;database=DATABASE;uid=sa;pwd=" />        
        private string connectionString;
        
public string ConntionString 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
return connectionString ; 
            }

            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                connectionString 
= value;
            }

        }



        
public DataBaseLayer(string strConnect,string dataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{            
            
this.ConntionString = strConnect;
            
this.DbType = dataType;
        }



        
public DataBaseLayer()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
this.connectionString = ConfigurationSettings.AppSettings["ConnectionString"] ;
            
this.dbType = ConfigurationSettings.AppSettings["DataType"] ;
            
//this.connectionString = "data source=192.168.1.43;user id=sa;pwd=sa;database=temphrdb";
            
//this.dbType = "SqlServer";
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 数据库类型 
        
/// </summary>

        private string dbType;
        
public string DbType
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if ( dbType == string.Empty || dbType == null )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
return "Access";
                }

                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
return dbType;
                }

            }

            
set  
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if ( value != string.Empty  &&  value != null )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    dbType 
= value;
                }

                
if (dbType ==string.Empty || dbType == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    dbType 
= ConfigurationSettings.AppSettings["DataType"];
                }

                
if ( dbType == string.Empty || dbType == null )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    dbType 
= "Access";
                }

            }
      
        }




        
ContractedSubBlock.gifExpandedSubBlockStart.gif        
转换参数#region 转换参数
        
private System.Data.IDbDataParameter iDbPara(string ParaName,string DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return GetSqlPara(ParaName,DataType);

                
case "Oracle":
                    
return GetOleDbPara(ParaName,DataType);

                
case "Access":
                    
return GetOleDbPara(ParaName,DataType);

                
default :
                    
return GetSqlPara(ParaName,DataType);

            }

        }


        
private System.Data.SqlClient.SqlParameter  GetSqlPara( string ParaName , string DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "Decimal":
                    
return  new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.Decimal );
                
case "Varchar":
                    
return new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.VarChar );
                
case "DateTime":
                    
return new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.DateTime );
                
case "Iamge":
                    
return new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.Image );
                
case "Int":
                    
return new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.Int );
                
case "Text":
                    
return new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.NText );
                
default :
                    
return new System.Data.SqlClient.SqlParameter ( ParaName, System.Data.SqlDbType.VarChar );
            }

        }


        
private System.Data.OracleClient.OracleParameter  GetOraclePara( string ParaName , string DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "Decimal":
                    
return  new System.Data.OracleClient.OracleParameter( ParaName, System.Data.OracleClient.OracleType.Double);
    
                
case "Varchar":
                    
return  new System.Data.OracleClient.OracleParameter ( ParaName, System.Data.OracleClient.OracleType.VarChar );

                
case "DateTime":
                    
return  new System.Data.OracleClient.OracleParameter ( ParaName, System.Data.OracleClient.OracleType.DateTime );

                
case "Iamge":
                    
return  new System.Data.OracleClient.OracleParameter ( ParaName, System.Data.OracleClient.OracleType.BFile );

                
case "Int":
                    
return  new System.Data.OracleClient.OracleParameter ( ParaName, System.Data.OracleClient.OracleType.Int32 );

                
case "Text":
                    
return  new System.Data.OracleClient.OracleParameter ( ParaName, System.Data.OracleClient.OracleType.LongVarChar );

                
default:
                    
return  new System.Data.OracleClient.OracleParameter ( ParaName, System.Data.OracleClient.OracleType.VarChar );

            }

        }


        
private System.Data.OleDb.OleDbParameter  GetOleDbPara( string ParaName , string DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(DataType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "Decimal":
                    
return  new System.Data.OleDb.OleDbParameter( ParaName, System.Data.DbType.Decimal);

                
case "Varchar":
                    
return  new System.Data.OleDb.OleDbParameter ( ParaName, System.Data.DbType.String );

                
case "DateTime":
                    
return  new System.Data.OleDb.OleDbParameter ( ParaName, System.Data.DbType.DateTime );

                
case "Iamge":
                    
return   new System.Data.OleDb.OleDbParameter( ParaName, System.Data.DbType.Binary );

                
case "Int":
                    
return  new System.Data.OleDb.OleDbParameter ( ParaName, System.Data.DbType.Int32 );

                
case "Text":
                    
return  new System.Data.OleDb.OleDbParameter ( ParaName, System.Data.DbType.String );                    

                
default:
                    
return  new System.Data.OleDb.OleDbParameter ( ParaName, System.Data.DbType.String );

            }

        }


        
#endregion

        
ContractedSubBlock.gifExpandedSubBlockStart.gif        
创建 Connection 和 Command#region 创建 Connection 和 Command

        
private IDbConnection GetConnection()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return new System.Data.SqlClient.SqlConnection(this.ConntionString);

                
case "Oracle":
                    
return new System.Data.OracleClient.OracleConnection(this.ConntionString);

                
case "Access":
                    
return new System.Data.OleDb.OleDbConnection(this.ConntionString);
                
default:
                    
return new System.Data.SqlClient.SqlConnection(this.ConntionString);
            }

        }


        
        
private IDbCommand GetCommand(string Sql,IDbConnection iConn)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return new System.Data.SqlClient.SqlCommand(Sql,(SqlConnection)iConn);

                
case "Oracle":
                    
return new System.Data.OracleClient.OracleCommand(Sql,(OracleConnection)iConn);
    
                
case "Access":
                    
return new System.Data.OleDb.OleDbCommand(Sql,(OleDbConnection)iConn);
                
default:
                    
return new System.Data.SqlClient.SqlCommand(Sql,(SqlConnection)iConn);
            }
    
        }


        
private IDbCommand GetCommand()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return new System.Data.SqlClient.SqlCommand();

                
case "Oracle":
                    
return new System.Data.OracleClient.OracleCommand();

                
case "Access":
                    
return new System.Data.OleDb.OleDbCommand();
                
default:
                    
return new System.Data.SqlClient.SqlCommand();
            }
    
        }


        
private IDataAdapter GetAdapater(string Sql,IDbConnection iConn)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return new System.Data.SqlClient.SqlDataAdapter(Sql,(SqlConnection)iConn);

                
case "Oracle":
                    
return new System.Data.OracleClient.OracleDataAdapter(Sql,(OracleConnection)iConn);

                
case "Access":
                    
return new System.Data.OleDb.OleDbDataAdapter(Sql,(OleDbConnection)iConn);

                
default:
                    
return new System.Data.SqlClient.SqlDataAdapter(Sql,(SqlConnection)iConn);;
            }

            
        }


        
private IDataAdapter GetAdapater()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return new System.Data.SqlClient.SqlDataAdapter();

                
case "Oracle":
                    
return new System.Data.OracleClient.OracleDataAdapter();

                
case "Access":
                    
return new System.Data.OleDb.OleDbDataAdapter();

                
default:
                    
return new System.Data.SqlClient.SqlDataAdapter();
            }

        }


        
private IDataAdapter GetAdapater(IDbCommand iCmd)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
switch(this.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
case "SqlServer":
                    
return new System.Data.SqlClient.SqlDataAdapter((SqlCommand)iCmd);

                
case "Oracle":
                    
return new System.Data.OracleClient.OracleDataAdapter((OracleCommand)iCmd);

                
case "Access":
                    
return new System.Data.OleDb.OleDbDataAdapter((OleDbCommand)iCmd);

                
default:
                    
return new System.Data.SqlClient.SqlDataAdapter((SqlCommand)iCmd);
            }

        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行简单SQL语句#region  执行简单SQL语句
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行SQL语句,返回影响的记录数
        
/// </summary>
        
/// <param name="SQLString">SQL语句</param>
        
/// <returns>影响的记录数</returns>

        public int ExecuteSql(string SqlString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{                
                
using (System.Data.IDbCommand iCmd  = GetCommand(SqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Open();
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{        
                        
                        
int rows=iCmd.ExecuteNonQuery();
                        
return rows;
                    }

                    
catch(System.Exception E)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                    
                        
throw new Exception(E.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }
                
            }

        }

        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行多条SQL语句,实现数据库事务。
        
/// </summary>
        
/// <param name="SQLStringList">多条SQL语句</param>        

        public  void ExecuteSqlTran(ArrayList SQLStringList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iConn.Open();
                
using(System.Data.IDbCommand iCmd  =  GetCommand())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iCmd.Connection
=iConn;                
                    
using(System.Data.IDbTransaction iDbTran = iConn.BeginTransaction())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iCmd.Transaction
=iDbTran;    
                        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{           
                            
for(int n=0;n<SQLStringList.Count;n++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
{
                                
string strsql = SQLStringList[n].ToString();
                                
if ( strsql.Trim().Length>1
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
{
                                    iCmd.CommandText 
= strsql;
                                    iCmd.ExecuteNonQuery();
                                }

                            }
                                        
                            iDbTran.Commit();                    
                        }

                        
catch(System.Exception E)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{        
                            iDbTran.Rollback();
                            
throw new Exception(E.Message);
                        }

                        
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
{
                                iConn.Close();
                            }

                        }

                    }


                }


            }

        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行带一个存储过程参数的的SQL语句。
        
/// </summary>
        
/// <param name="SQLString">SQL语句</param>
        
/// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
        
/// <returns>影响的记录数</returns>

        public int ExecuteSql(string SqlString,string content)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{                
            
using (System.Data.IDbConnection  iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
using(System.Data.IDbCommand iCmd  = GetCommand(SqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    System.Data.IDataParameter  myParameter 
= this.iDbPara( "@content""Text");
                    myParameter.Value 
= content ;
                    iCmd.Parameters.Add(myParameter);
                    iConn.Open();
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
                        
int rows = iCmd.ExecuteNonQuery();
                        
return rows;
                    }

                    
catch( System.Exception e )
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(e.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }

            }

        }
        


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 向数据库里插入图像格式的字段(和上面情况类似的另一种实例)
        
/// </summary>
        
/// <param name="strSQL">SQL语句</param>
        
/// <param name="fs">图像字节,数据库的字段类型为image的情况</param>
        
/// <returns>影响的记录数</returns>

        public int ExecuteSqlInsertImg(string SqlString,byte[] fs)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{        
            
using (System.Data.IDbConnection  iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
using(System.Data.IDbCommand iCmd  = GetCommand(SqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    System.Data.IDataParameter  myParameter 
= this.iDbPara( "@content""Image");
                    myParameter.Value 
= fs ;
                    iCmd.Parameters.Add(myParameter);
                    iConn.Open();
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
int rows = iCmd.ExecuteNonQuery();
                        
return rows;
                    }

                    
catch( System.Exception e )
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(e.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }
    
            }

        }

        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行一条计算查询结果语句,返回查询结果(object)。
        
/// </summary>
        
/// <param name="SQLString">计算查询结果语句</param>
        
/// <returns>查询结果(object)</returns>

        public  object GetSingle(string SqlString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
using (System.Data.IDbCommand iCmd  =  GetCommand(SqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Open();
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
object obj = iCmd.ExecuteScalar();
                        
if((Object.Equals(obj,null))||(Object.Equals(obj,System.DBNull.Value)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{                    
                            
return null;
                        }

                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            
return obj;
                        }
                
                    }

                    
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                        
                        
throw new Exception(e.Message);
                    }
    
                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }

            }

        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句,返回IDataAdapter
        
/// </summary>
        
/// <param name="strSQL">查询语句</param>
        
/// <returns>IDataAdapter</returns>

        public IDataAdapter ExecuteReader(string strSQL)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iConn.Open();    
                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{    
                    System.Data.IDataAdapter iAdapter 
= this.GetAdapater(strSQL,iConn);
                    
return iAdapter;
                }

                
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{                                
                    
throw new Exception(e.Message);
                }
        
                
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iConn.Close();
                    }

                }
    
            }

        }
        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句,返回DataSet
        
/// </summary>
        
/// <param name="SQLString">查询语句</param>
        
/// <returns>DataSet</returns>

        public DataSet Query(string sqlString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{    
                
using(System.Data.IDbCommand iCmd  =  GetCommand(sqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    DataSet ds 
= new DataSet();
                    iConn.Open();    
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        System.Data.IDataAdapter iAdapter 
= this.GetAdapater(sqlString,iConn);
                        iAdapter.Fill(ds);
                        
return ds;
                    }

                    
catch(System.Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(ex.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }

            }
            
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句,返回DataSet
        
/// </summary>
        
/// <param name="sqlString">查询语句</param>
        
/// <param name="dataSet">要填充的DataSet</param>
        
/// <param name="tableName">要填充的表名</param>
        
/// <returns>DataSet</returns>

        public DataSet Query(string sqlString,DataSet dataSet,string tableName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{    
                
using(System.Data.IDbCommand iCmd  =  GetCommand(sqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Open();    
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        System.Data.IDataAdapter iAdapter 
= this.GetAdapater(sqlString,iConn);
                        ((OleDbDataAdapter)iAdapter).Fill(dataSet,tableName);
                        
return dataSet;
                    }

                    
catch(System.Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(ex.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }
    
            }
            
        }



ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行SQL语句 返回存储过程
        
/// </summary>
        
/// <param name="sqlString">Sql语句</param>
        
/// <param name="dataSet">要填充的DataSet</param>
        
/// <param name="startIndex">开始记录</param>
        
/// <param name="pageSize">页面记录大小</param>
        
/// <param name="tableName">表名称</param>
        
/// <returns>DataSet</returns>

        public DataSet Query(string sqlString , DataSet dataSet ,int  startIndex ,int pageSize, string tableName )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{                    
                iConn.Open();
                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    System.Data.IDataAdapter iAdapter 
= this.GetAdapater(sqlString,iConn);

                    ((OleDbDataAdapter)iAdapter).Fill(dataSet,startIndex,pageSize,tableName);        
        
                    
return dataSet;
                }

                
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
throw new Exception(ex.Message);
                }

                
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iConn.Close();
                    }

                }

            }

        }



ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句,向XML文件写入数据
        
/// </summary>
        
/// <param name="sqlString">查询语句</param>
        
/// <param name="xmlPath">XML文件路径</param>

        public void WriteToXml(string sqlString,string xmlPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            Query(sqlString).WriteXml(xmlPath);
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句
        
/// </summary>
        
/// <param name="SqlString">查询语句</param>
        
/// <returns>DataTable </returns>

        public DataTable ExecuteQuery(string sqlString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{    
                
//System.Data.IDbCommand iCmd  =  GetCommand(sqlString,iConn);
                DataSet ds = new DataSet();
                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    System.Data.IDataAdapter iAdapter 
= this.GetAdapater(sqlString,iConn);            
                    iAdapter.Fill(ds);
                }

                
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{                
                    
throw new Exception(e.Message);
                }
    
                
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iConn.Close();
                    }

                }

                
return ds.Tables[0];
            }

        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句
        
/// </summary>
        
/// <param name="SqlString">查询语句</param>
        
/// <returns>DataTable </returns>

        public DataTable ExecuteQuery(string SqlString,string Proc)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{    
                
using(System.Data.IDbCommand iCmd  =  GetCommand(SqlString,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iCmd.CommandType 
= CommandType.StoredProcedure;
                    DataSet ds 
= new DataSet();
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        System.Data.IDataAdapter iDataAdapter 
= this.GetAdapater(SqlString,iConn);            
                        iDataAdapter.Fill(ds);
                    }

                    
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(e.Message);
                    }
    
                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                    
return ds.Tables[0];
                }

        
                
            }

        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 
        
/// </summary>
        
/// <param name="Sql"></param>
        
/// <returns></returns>

        public DataView ExeceuteDataView(string Sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{    
                
using(System.Data.IDbCommand iCmd  =  GetCommand(Sql,iConn))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    DataSet ds 
= new DataSet();
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        System.Data.IDataAdapter iDataAdapter 
= this.GetAdapater(Sql,iConn);            
                        iDataAdapter.Fill(ds);
                        
return ds.Tables[0].DefaultView;
                    }

                    
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(e.Message);
                    }
    
                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }
    
            }

        }


        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行带参数的SQL语句#region 执行带参数的SQL语句
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行SQL语句,返回影响的记录数
        
/// </summary>
        
/// <param name="SQLString">SQL语句</param>
        
/// <returns>影响的记录数</returns>

        public  int ExecuteSql(string SQLString,params IDataParameter[] iParms)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{    
                System.Data.IDbCommand iCmd  
=  GetCommand();
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{        
                        PrepareCommand(
out iCmd, iConn, null , SQLString, iParms );
                        
int rows=iCmd.ExecuteNonQuery();
                        iCmd.Parameters.Clear();
                        
return rows;
                    }

                    
catch(System.Exception E)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception( E.Message );
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iCmd.Dispose();
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }
                
            }

        }

        
            
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行多条SQL语句,实现数据库事务。
        
/// </summary>
        
/// <param name="SQLStringList">SQL语句的哈希表(key为sql语句,value是该语句的SqlParameter[])</param>

        public void ExecuteSqlTran(Hashtable SQLStringList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{            
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iConn.Open();
                
using (IDbTransaction  iTrans = iConn.BeginTransaction()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    System.Data.IDbCommand iCmd  
=  GetCommand();
                    
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
//循环
                        foreach ( DictionaryEntry myDE in SQLStringList)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{    
                            
string     cmdText = myDE.Key.ToString();
                            IDataParameter[] iParms
=( IDataParameter[] ) myDE.Value;
                            PrepareCommand( 
out iCmd , iConn , iTrans , cmdText , iParms );
                            
int val = iCmd.ExecuteNonQuery();
                            iCmd.Parameters.Clear();
                        }

                        iTrans.Commit();                
                    }

                    
catch 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iTrans.Rollback();
                        
throw;
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iCmd.Dispose();
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }


                }
                
            }

        }

    
                
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行一条计算查询结果语句,返回查询结果(object)。
        
/// </summary>
        
/// <param name="SQLString">计算查询结果语句</param>
        
/// <returns>查询结果(object)</returns>

        public object GetSingle(string SQLString,params IDataParameter[] iParms)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                System.Data.IDbCommand iCmd  
=  GetCommand();    
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        PrepareCommand( 
out iCmd, iConn, null , SQLString, iParms );
                        
object obj = iCmd.ExecuteScalar();
                        iCmd.Parameters.Clear();
                        
if((Object.Equals(obj,null))||(Object.Equals(obj,System.DBNull.Value)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{                    
                            
return null;
                        }

                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            
return obj;
                        }
                
                    }

                    
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(e.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iCmd.Dispose();
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }

            }

        }

        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句,返回IDataReader
        
/// </summary>
        
/// <param name="strSQL">查询语句</param>
        
/// <returns> IDataReader </returns>

        public IDataReader ExecuteReader(string SQLString,params IDataParameter[] iParms)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{        
            System.Data.IDbConnection  iConn 
= this.GetConnection();
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                System.Data.IDbCommand iCmd  
=  GetCommand();
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        PrepareCommand(
out iCmd, iConn , null , SQLString , iParms);
                        System.Data.IDataReader iReader 
= iCmd.ExecuteReader();
                        iCmd.Parameters.Clear();
                        
return iReader;
                    }

                    
catch(System.Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                                
                        
throw new Exception(e.Message);
                    }
        
                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iCmd.Dispose();
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }
            
                }

            }
    
        }
        
        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行查询语句,返回DataSet
        
/// </summary>
        
/// <param name="SQLString">查询语句</param>
        
/// <returns>DataSet</returns>

        public DataSet Query(string sqlString,params IDataParameter[] iParms)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                IDbCommand iCmd 
= GetCommand();
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    PrepareCommand(
out iCmd , iConn , null , sqlString , iParms );
                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{    
                        IDataAdapter iAdapter 
=  this.GetAdapater(sqlString,iConn);
                        DataSet ds 
= new DataSet();                                                
                        iAdapter.Fill(ds);
                        iCmd.Parameters.Clear();
                        
return ds;
                    }

                    
catch(System.Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{                
                        
throw new Exception(ex.Message);
                    }

                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iCmd.Dispose();
                        
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
{
                            iConn.Close();
                        }

                    }

                }
    
            }

        }

        
        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 初始化Command
        
/// </summary>
        
/// <param name="iCmd"></param>
        
/// <param name="iConn"></param>
        
/// <param name="iTrans"></param>
        
/// <param name="cmdText"></param>
        
/// <param name="iParms"></param>

        private void PrepareCommand(out IDbCommand iCmd,IDbConnection iConn,System.Data.IDbTransaction iTrans, string cmdText, IDataParameter[] iParms) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (iConn.State != ConnectionState.Open)
                iConn.Open();
            iCmd 
= this.GetCommand();
            iCmd.Connection 
=  iConn;
            iCmd.CommandText 
= cmdText;
            
if (iTrans != null)
                iCmd.Transaction 
= iTrans;
            iCmd.CommandType 
= CommandType.Text;//cmdType;
            if (iParms != null
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
foreach (IDataParameter parm in iParms)
                    iCmd.Parameters.Add(parm);
            }

        }


        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
存储过程操作#region 存储过程操作

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行存储过程
        
/// </summary>
        
/// <param name="storedProcName">存储过程名</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <returns>SqlDataReader</returns>

        public SqlDataReader RunProcedure(string storedProcName, IDataParameter[] parameters )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            System.Data.IDbConnection  iConn 
= this.GetConnection();
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iConn.Open();
                
                
using(SqlCommand sqlCmd = BuildQueryCommand(iConn,storedProcName, parameters))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
return  sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);    
                }

            }

        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行存储过程
        
/// </summary>
        
/// <param name="storedProcName">存储过程名</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <param name="tableName">DataSet结果中的表名</param>
        
/// <returns>DataSet</returns>

        public  DataSet RunProcedure(string storedProcName, IDataParameter[] parameters ,string tableName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{

            
using (System.Data.IDbConnection   iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                DataSet dataSet 
= new DataSet();
                iConn.Open();
                System.Data.IDataAdapter iDA 
= this.GetAdapater();
                iDA 
= this.GetAdapater( BuildQueryCommand(iConn, storedProcName, parameters ) );

                ((SqlDataAdapter)iDA).Fill( dataSet,tableName);
                
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Close();
                }

                
return dataSet;
            }

        }




ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行存储过程
        
/// </summary>
        
/// <param name="storedProcName">存储过程名</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <param name="tableName">DataSet结果中的表名</param>
        
/// <param name="startIndex">开始记录索引</param>
        
/// <param name="pageSize">页面记录大小</param>
        
/// <returns>DataSet</returns>

        public  DataSet RunProcedure(string storedProcName, IDataParameter[] parameters ,int startIndex,int pageSize,string tableName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{

            
using (System.Data.IDbConnection   iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                DataSet dataSet 
= new DataSet();
                iConn.Open();
                System.Data.IDataAdapter iDA 
= this.GetAdapater();
                iDA 
= this.GetAdapater( BuildQueryCommand(iConn, storedProcName, parameters ) );

                ((SqlDataAdapter)iDA).Fill( dataSet,startIndex,pageSize,tableName);
                
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Close();
                }

                
return dataSet;
            }

        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行存储过程 填充已经存在的DataSet数据集 
        
/// </summary>
        
/// <param name="storeProcName">存储过程名称</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <param name="dataSet">要填充的数据集</param>
        
/// <param name="tablename">要填充的表名</param>
        
/// <returns></returns>

        public DataSet RunProcedure(string storeProcName,IDataParameter[] parameters,DataSet dataSet,string tableName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iConn.Open();
                System.Data.IDataAdapter iDA 
= this.GetAdapater();
                iDA 
= this.GetAdapater(BuildQueryCommand(iConn,storeProcName,parameters));
                
                ((SqlDataAdapter)iDA).Fill(dataSet,tableName);
                
                
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Close();
                }


                
return dataSet;
            }

        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行存储过程并返回受影响的行数
        
/// </summary>
        
/// <param name="storedProcName"></param>
        
/// <param name="parameters"></param>
        
/// <returns></returns>

        public int RunProcedureNoQuery(string storedProcName, IDataParameter[] parameters )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{

            
int result = 0;
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iConn.Open();
                
using(SqlCommand scmd = BuildQueryCommand(iConn,storedProcName,parameters))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    result 
= scmd.ExecuteNonQuery();
                }
    

                
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Close();
                }

            }


            
return result ;
        }


        
public string RunProcedureExecuteScalar(string storeProcName,IDataParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
string result = string.Empty;
            
using (System.Data.IDbConnection iConn = this.GetConnection())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
                iConn.Open();
                
using(SqlCommand scmd = BuildQueryCommand(iConn,storeProcName,parameters))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
object obj = scmd.ExecuteScalar();
                    
if(obj == null)
                        result 
= null;
                    
else
                        result 
= obj.ToString();
                }


                
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    iConn.Close();
                }


            }


            
return result;
        }

        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 构建 SqlCommand 对象(用来返回一个结果集,而不是一个整数值)
        
/// </summary>
        
/// <param name="connection">数据库连接</param>
        
/// <param name="storedProcName">存储过程名</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <returns>SqlCommand</returns>

        private SqlCommand BuildQueryCommand(IDbConnection iConn,string storedProcName, IDataParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{            
            
            IDbCommand iCmd 
= GetCommand(storedProcName,iConn);
            iCmd.CommandType 
= CommandType.StoredProcedure;
            
if (parameters == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
return (SqlCommand)iCmd;
            }

            
foreach (IDataParameter parameter in parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                iCmd.Parameters.Add( parameter );
            }

            
return (SqlCommand)iCmd;            
        }

        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 执行存储过程,返回影响的行数        
        
/// </summary>
        
/// <param name="storedProcName">存储过程名</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <param name="rowsAffected">影响的行数</param>
        
/// <returns></returns>

        public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
using (System.Data.IDbConnection  iConn = this.GetConnection())    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
int result;
                iConn.Open();
                
using(SqlCommand sqlCmd = BuildIntCommand(iConn,storedProcName, parameters ))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    rowsAffected 
= sqlCmd.ExecuteNonQuery();
                    result 
= (int)sqlCmd.Parameters["ReturnValue"].Value;

                    
if(iConn.State != ConnectionState.Closed)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        iConn.Close();
                    }

                    
return result;                
                }

            }

        }

        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 创建 SqlCommand 对象实例(用来返回一个整数值)    
        
/// </summary>
        
/// <param name="storedProcName">存储过程名</param>
        
/// <param name="parameters">存储过程参数</param>
        
/// <returns>SqlCommand 对象实例</returns>

        private SqlCommand BuildIntCommand(IDbConnection iConn,string storedProcName, IDataParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            SqlCommand sqlCmd 
= BuildQueryCommand(iConn,storedProcName, parameters );
            sqlCmd.Parameters.Add( 
new SqlParameter ( "ReturnValue",
                SqlDbType.Int,
4,ParameterDirection.ReturnValue,
                
false,0,0,string.Empty,DataRowVersion.Default,null ));
            
return sqlCmd;
        }

        
#endregion
    


    }

}



  代码下载

转载于:https://www.cnblogs.com/shanlanyu/archive/2007/06/06/773924.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值