利用DbProviderFactory实现数据操作跨数据库数据操作类.

 

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text;
None.gif
using  System.Data;
None.gif
using  System.Data.Common;
None.gif
using  System.Configuration;
None.gif
using  System.Collections;
None.gif
None.gif
namespace  Ths
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// ========================================================
InBlock.gif    
/// 2006-9-13
InBlock.gif    
/// Wangzhq
InBlock.gif    
/// zhenqiang812@163.com
InBlock.gif    
/// wangzhq.cnblogs.com
InBlock.gif    
/// 数据工厂类,实现了跨数据库的操作.
InBlock.gif    
/// ========================================================
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class DataAccess:PageBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Webconfig配置连接字符串
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private string _confirString = "ConnectionString";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 数据工厂类
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public DataAccess()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 数据工厂类
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="configString">web.config 关键字</param>

InBlock.gif        public DataAccess(string configString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ConfigString 
= configString;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 属性,设置数据库连接字符串
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string ConfigString
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _confirString;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _confirString 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//==============================================GetProviderName==============================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
获得数据库的类型 public string GetProviderName(string ConfigString)#region 获得数据库的类型 public string GetProviderName(string ConfigString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 返回数据提供者
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <returns>返回数据提供者</returns>

InBlock.gif        public string GetProviderName(string ConfigString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif           
InBlock.gif            ConnectionStringSettingsCollection ConfigStringCollention 
= ConfigurationManager.ConnectionStrings;
InBlock.gif            
if (ConfigStringCollention == null || ConfigStringCollention.Count <= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw new Exception("web.config 中无连接字符串!");
ExpandedSubBlockEnd.gif            }

InBlock.gif            ConnectionStringSettings StringSettings 
= null;
InBlock.gif            
if (ConfigString == string.Empty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                StringSettings 
= ConfigurationManager.ConnectionStrings["ConnectionString"];
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                StringSettings 
= ConfigurationManager.ConnectionStrings[ConfigString];
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return StringSettings.ProviderName;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 返回数据提供者
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public string GetProviderName()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return GetProviderName(ConfigString);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=====================================================获得连接字符串====================================
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获得连接字符串
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public string GetConnectionString(string ConfigString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ConnectionStringSettingsCollection ConfigStringCollention 
= ConfigurationManager.ConnectionStrings;
InBlock.gif            
if (ConfigStringCollention == null || ConfigStringCollention.Count <= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw new Exception("web.config 中无连接字符串!");
ExpandedSubBlockEnd.gif            }

InBlock.gif            ConnectionStringSettings StringSettings 
= null;
InBlock.gif            
if (ConfigString == string.Empty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                StringSettings 
= ConfigurationManager.ConnectionStrings["ConnectionString"];
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                StringSettings 
= ConfigurationManager.ConnectionStrings[ConfigString];
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return StringSettings.ConnectionString;
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public string GetConnectionString()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return GetConnectionString(ConfigString);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
//==============================================GetDbproviderFactory=========================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
返回数据工厂  public DbProviderFactory GetDbProviderFactory()#region 返回数据工厂  public DbProviderFactory GetDbProviderFactory()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 返回数据工厂
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public DbProviderFactory GetDbProviderFactory()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbProviderFactory f 
= null;
InBlock.gif            
string ProviderName = GetProviderName();
InBlock.gif            
switch (ProviderName)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
case "System.Data.SqlClient":
InBlock.gif                    f 
= GetDbProviderFactory("System.Data.SqlClient");
InBlock.gif                    
break;
InBlock.gif                
case "System.Data.OracleClient":
InBlock.gif                    f 
= GetDbProviderFactory("System.Data.OracleClient");
InBlock.gif                    
break;
InBlock.gif                
case "System.Data.OleDb":
InBlock.gif                    f 
= GetDbProviderFactory("System.Data.OleDb");
InBlock.gif                    
break;
InBlock.gif                
default:
InBlock.gif                    f 
= GetDbProviderFactory("System.Data.SqlClient");
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return f;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 返回数据工厂
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="providername"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public DbProviderFactory GetDbProviderFactory(string providername)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return DbProviderFactories.GetFactory(providername);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//==============================================CreateConnection=============================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
创建数据库连接 public DbConnection CreateConnection()#region 创建数据库连接 public DbConnection CreateConnection()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建数据库连接
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public DbConnection CreateConnection()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbConnection con 
= GetDbProviderFactory().CreateConnection();
InBlock.gif            con.ConnectionString 
= GetConnectionString();
InBlock.gif
InBlock.gif            
return con;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建数据库连接
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="provdername"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public DbConnection CreateConnection(string provdername)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbConnection con 
= GetDbProviderFactory(provdername).CreateConnection();
InBlock.gif            con.ConnectionString 
= GetConnectionString();
InBlock.gif
InBlock.gif            
return con;
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//==============================================CreateCommand================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
创建执行命令对象 public override DbCommand CreateCommand(string sql, CommandType cmdType, DbParameter[] parameters)#region 创建执行命令对象 public override DbCommand CreateCommand(string sql, CommandType cmdType, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建执行命令对象
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql"></param>
InBlock.gif        
/// <param name="cmdType"></param>
InBlock.gif        
/// <param name="parameters"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public DbCommand CreateCommand(string sql, CommandType cmdType, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbCommand _command 
= GetDbProviderFactory().CreateCommand();
InBlock.gif            _command.Connection 
= CreateConnection();
InBlock.gif            _command.CommandText 
= sql;
InBlock.gif            _command.CommandType 
= cmdType;
InBlock.gif            
if (parameters != null && parameters.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach (DbParameter param in parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _command.Parameters.Add(param);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return _command;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建执行命令对象
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>执行命令对象实例</returns>

InBlock.gif        public DbCommand CreateCommand(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return CreateCommand(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建执行命令对象
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>执行命令对象实例</returns>

InBlock.gif        public DbCommand CreateCommand(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return CreateCommand(sql, cmdtype, parameters);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建执行命令对象
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>执行命令对象实例</returns>

InBlock.gif        public DbCommand CreateCommand(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return CreateCommand(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=========================================CreateAdapter()==============================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
创建数据适配器 CreateAdapter(string sql)#region 创建数据适配器 CreateAdapter(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建数据适配器
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL,语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>数据适配器实例</returns>

InBlock.gif        public DbDataAdapter CreateAdapter(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return CreateAdapter(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建数据适配器
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
ExpandedSubBlockEnd.gif        
/// <returns>数据适配器实例</returns>

InBlock.gif        public DbDataAdapter CreateAdapter(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return CreateAdapter(sql, cmdtype, parameters);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建数据适配器
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="connectionString">数据库连接字符串</param>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>数据适配器实例</returns>

InBlock.gif        public DbDataAdapter CreateAdapter(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbConnection _connection 
= CreateConnection();
InBlock.gif            DbCommand _command 
= GetDbProviderFactory().CreateCommand();
InBlock.gif            _command.Connection 
= _connection;
InBlock.gif            _command.CommandText 
= sql;
InBlock.gif            _command.CommandType 
= cmdtype;
InBlock.gif            
if (parameters != null && parameters.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach (DbParameter _param in parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _command.Parameters.Add(_param);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            DbDataAdapter da 
= GetDbProviderFactory().CreateDataAdapter();
InBlock.gif            da.SelectCommand 
= _command;
InBlock.gif
InBlock.gif            
return da;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=========================================CreateParameter===================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
生成参数 public override SqlParameter CreateParameter(string field, string dbtype, string value)#region 生成参数 public override SqlParameter CreateParameter(string field, string dbtype, string value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建参数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="field">参数字段</param>
InBlock.gif        
/// <param name="dbtype">参数类型</param>
InBlock.gif        
/// <param name="value">参数值</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public DbParameter CreateParameter(string field, string dbtype, string value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter p 
= GetDbProviderFactory().CreateParameter();
InBlock.gif            p.ParameterName 
= field;
InBlock.gif            p.Value 
= value;
InBlock.gif            
return p;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//======================================================ExecuteCommand()============================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行非查询语句,并返回受影响的记录行数 ExecuteCommand(string sql)#region 执行非查询语句,并返回受影响的记录行数 ExecuteCommand(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回受影响的记录行数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>受影响记录行数</returns>

InBlock.gif        public int ExecuteCommand(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return ExecuteCommand(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回受影响的记录行数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
ExpandedSubBlockEnd.gif        
/// <returns>受影响记录行数</returns>

InBlock.gif        public int ExecuteCommand(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return ExecuteCommand(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回受影响的记录行数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>受影响记录行数</returns>

InBlock.gif        public int ExecuteCommand(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return ExecuteCommand(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///批量执行SQL语句 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="SqlList">SQL列表</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public bool ExecuteCommand(ArrayList SqlList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbConnection con 
= CreateConnection();
InBlock.gif            con.Open();
InBlock.gif            
bool iserror = false;
InBlock.gif            
string strerror = "";
InBlock.gif            DbTransaction SqlTran 
=con.BeginTransaction();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for (int i = 0; i < SqlList.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif
InBlock.gif                    DbCommand _command 
= GetDbProviderFactory().CreateCommand();
InBlock.gif                    _command.Connection 
= con;
InBlock.gif                    _command.CommandText 
= SqlList[i].ToString();
InBlock.gif                    _command.Transaction 
= SqlTran;
InBlock.gif                    _command.ExecuteNonQuery();
ExpandedSubBlockEnd.gif                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                iserror 
= true;
InBlock.gif                strerror 
= ex.Message;
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                
if (iserror)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    SqlTran.Rollback();
InBlock.gif                    
throw new Exception(strerror);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    SqlTran.Commit();
ExpandedSubBlockEnd.gif                }

InBlock.gif                con.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (iserror)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回受影响的记录行数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>受影响记录行数</returns>

InBlock.gif        public int ExecuteCommand(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int _result = 0;
InBlock.gif            DbCommand _command 
= CreateCommand(sql, cmdtype, parameters);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _command.Connection.Open();
InBlock.gif                _result 
= _command.ExecuteNonQuery();
ExpandedSubBlockEnd.gif            }

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

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _command.Connection.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return _result;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=====================================================ExecuteScalar()=============================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行非查询语句,并返回首行首列的值 ExecuteScalar(string sql)#region 执行非查询语句,并返回首行首列的值 ExecuteScalar(string sql)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回首行首列的值
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>Object</returns>

InBlock.gif        public object ExecuteScalar(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return ExecuteScalar(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回首行首列的值
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
ExpandedSubBlockEnd.gif        
/// <returns>Object</returns>

InBlock.gif        public object ExecuteScalar(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return ExecuteScalar(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回首行首列的值
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>Object</returns>

InBlock.gif        public object ExecuteScalar(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return ExecuteScalar(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行非查询语句,并返回首行首列的值
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>Object</returns>

InBlock.gif        public object ExecuteScalar(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
object _result=null;
InBlock.gif            DbCommand _command 
= CreateCommand(sql, cmdtype, parameters);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _command.Connection.Open();
InBlock.gif                _result 
= _command.ExecuteScalar();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _command.Connection.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return _result;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=====================================================ExecuteReader()=============================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行查询,并以DataReader返回结果集  ExecuteReader(string sql)#region 执行查询,并以DataReader返回结果集  ExecuteReader(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataReader返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>IDataReader</returns>

InBlock.gif        public DbDataReader ExecuteReader(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return ExecuteReader(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataReader返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
ExpandedSubBlockEnd.gif        
/// <returns>IDataReader</returns>

InBlock.gif        public DbDataReader ExecuteReader(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return ExecuteReader(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataReader返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>IDataReader</returns>

InBlock.gif        public DbDataReader ExecuteReader(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return ExecuteReader(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataReader返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>IDataReader</returns>

InBlock.gif        public DbDataReader ExecuteReader(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbDataReader _result;
InBlock.gif            DbCommand _command 
= CreateCommand(sql, cmdtype, parameters);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _command.Connection.Open();
InBlock.gif                _result 
= _command.ExecuteReader(CommandBehavior.CloseConnection);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return _result;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=====================================================GetDataSet()================================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行查询,并以DataSet返回结果集 GetDataSet(string sql)#region 执行查询,并以DataSet返回结果集 GetDataSet(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataSet返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataSet</returns>

InBlock.gif        public DataSet GetDataSet(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return GetDataSet(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataSet返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataSet</returns>

InBlock.gif        public virtual DataSet GetDataSet(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            
return GetDataSet(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataSet返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataSet</returns>

InBlock.gif        public virtual DataSet GetDataSet(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return GetDataSet(sql, CommandType.Text, parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataSet返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataSet</returns>

InBlock.gif        public virtual DataSet GetDataSet(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataSet _result 
= new DataSet();
InBlock.gif            IDataAdapter _dataAdapter 
= CreateAdapter(sql, cmdtype, parameters);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _dataAdapter.Fill(_result);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return _result;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataSet返回指定记录的结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="StartIndex">开始索引</param>
InBlock.gif        
/// <param name="RecordCount">显示记录</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataSet</returns>

InBlock.gif        public virtual DataSet GetDataSet(string sql, int StartIndex, int RecordCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return GetDataSet(sql, StartIndex, RecordCount);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=====================================================GetDataView()===============================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行查询,并以DataView返回结果集   GetDataView(string sql)#region 执行查询,并以DataView返回结果集   GetDataView(string sql)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataView返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataView</returns>

InBlock.gif        public DataView GetDataView(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            DataView dv 
= GetDataSet(sql, CommandType.Text, parameters).Tables[0].DefaultView;
InBlock.gif            
return dv;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataView返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataView</returns>

InBlock.gif        public DataView GetDataView(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            DataView dv 
= GetDataSet(sql, cmdtype, parameters).Tables[0].DefaultView;
InBlock.gif            
return dv;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataView返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataView</returns>

InBlock.gif        public DataView GetDataView(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            DataView dv 
= GetDataSet(sql, CommandType.Text, parameters).Tables[0].DefaultView;
InBlock.gif            
return dv;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataView返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataView</returns>

InBlock.gif        public DataView GetDataView(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataView dv 
= GetDataSet(sql, cmdtype, parameters).Tables[0].DefaultView;
InBlock.gif            
return dv;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataView返回指定记录的结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="StartIndex">开始索引</param>
InBlock.gif        
/// <param name="RecordCount">显示记录</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataView</returns>

InBlock.gif        public DataView GetDataView(string sql, int StartIndex, int RecordCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return GetDataSet(sql, StartIndex, RecordCount).Tables[0].DefaultView;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
//=====================================================GetDataTable()==============================================
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
执行查询,并以DataTable返回结果集   GetDataTable(string sql)#region 执行查询,并以DataTable返回结果集   GetDataTable(string sql)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataTable返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataTable</returns>

InBlock.gif        public DataTable GetDataTable(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            DataTable dt 
= GetDataSet(sql, CommandType.Text, parameters).Tables[0];
InBlock.gif            
return dt;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataTable返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataTable</returns>

InBlock.gif        public DataTable GetDataTable(string sql, CommandType cmdtype)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DbParameter[] parameters 
= new DbParameter[0];
InBlock.gif            DataTable dt 
= GetDataSet(sql, cmdtype, parameters).Tables[0];
InBlock.gif            
return dt;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataTable返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataTable</returns>

InBlock.gif        public DataTable GetDataTable(string sql, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            DataTable dt 
= GetDataSet(sql, CommandType.Text, parameters).Tables[0];
InBlock.gif            
return dt;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataTable返回结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="cmdtype">命令类型</param>
InBlock.gif        
/// <param name="parameters">参数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataTable</returns>

InBlock.gif        public DataTable GetDataTable(string sql, CommandType cmdtype, DbParameter[] parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataTable dt 
= GetDataSet(sql, cmdtype, parameters).Tables[0];
InBlock.gif            
return dt;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,并以DataTable返回指定记录的结果集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="StartIndex">开始索引</param>
InBlock.gif        
/// <param name="RecordCount">显示记录</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataTable</returns>

InBlock.gif        public DataTable GetDataTable(string sql, int StartIndex, int RecordCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return GetDataSet(sql, StartIndex, RecordCount).Tables[0];
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行查询,返回以空行填充的指定条数记录集
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sql">SQL语句</param>
InBlock.gif        
/// <param name="SizeCount">显示记录条数</param>
ExpandedSubBlockEnd.gif        
/// <returns>DataTable</returns>

InBlock.gif        public DataTable GetDataTable(string sql, int SizeCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataTable dt 
= GetDataSet(sql).Tables[0];
InBlock.gif            
int b = SizeCount - dt.Rows.Count;
InBlock.gif            
if (dt.Rows.Count < SizeCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for (int i = 0; i < b; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DataRow dr 
= dt.NewRow();
InBlock.gif                    dt.Rows.Add(dr);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return dt;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif

转载于:https://www.cnblogs.com/wangzhq/archive/2006/09/14/504309.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值