using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Data;
using
System.Data.Common;
using
System.Configuration;
using
System.Collections;
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace
Ths
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// ========================================================
/// 2006-9-13
/// Wangzhq
/// zhenqiang812@163.com
/// wangzhq.cnblogs.com
/// 数据工厂类,实现了跨数据库的操作.
/// ========================================================
/// </summary>
public class DataAccess:PageBase
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Webconfig配置连接字符串
/// </summary>
private string _confirString = "ConnectionString";
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 数据工厂类
/// </summary>
public DataAccess()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 数据工厂类
/// </summary>
/// <param name="configString">web.config 关键字</param>
public DataAccess(string configString)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ConfigString = configString;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 属性,设置数据库连接字符串
/// </summary>
public string ConfigString
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _confirString;
}
set
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_confirString = value;
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//==============================================GetProviderName==============================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
获得数据库的类型 public string GetProviderName(string ConfigString)#region 获得数据库的类型 public string GetProviderName(string ConfigString)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回数据提供者
/// </summary>
/// <returns>返回数据提供者</returns>
public string GetProviderName(string ConfigString)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ConnectionStringSettingsCollection ConfigStringCollention = ConfigurationManager.ConnectionStrings;
if (ConfigStringCollention == null || ConfigStringCollention.Count <= 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("web.config 中无连接字符串!");
}
ConnectionStringSettings StringSettings = null;
if (ConfigString == string.Empty)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringSettings = ConfigurationManager.ConnectionStrings["ConnectionString"];
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringSettings = ConfigurationManager.ConnectionStrings[ConfigString];
}
return StringSettings.ProviderName;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回数据提供者
/// </summary>
/// <returns></returns>
public string GetProviderName()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetProviderName(ConfigString);
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=====================================================获得连接字符串====================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 获得连接字符串
/// </summary>
/// <returns></returns>
public string GetConnectionString(string ConfigString)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ConnectionStringSettingsCollection ConfigStringCollention = ConfigurationManager.ConnectionStrings;
if (ConfigStringCollention == null || ConfigStringCollention.Count <= 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("web.config 中无连接字符串!");
}
ConnectionStringSettings StringSettings = null;
if (ConfigString == string.Empty)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringSettings = ConfigurationManager.ConnectionStrings["ConnectionString"];
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringSettings = ConfigurationManager.ConnectionStrings[ConfigString];
}
return StringSettings.ConnectionString;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
public string GetConnectionString()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetConnectionString(ConfigString);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//==============================================GetDbproviderFactory=========================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
返回数据工厂 public DbProviderFactory GetDbProviderFactory()#region 返回数据工厂 public DbProviderFactory GetDbProviderFactory()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回数据工厂
/// </summary>
/// <returns></returns>
public DbProviderFactory GetDbProviderFactory()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbProviderFactory f = null;
string ProviderName = GetProviderName();
switch (ProviderName)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case "System.Data.SqlClient":
f = GetDbProviderFactory("System.Data.SqlClient");
break;
case "System.Data.OracleClient":
f = GetDbProviderFactory("System.Data.OracleClient");
break;
case "System.Data.OleDb":
f = GetDbProviderFactory("System.Data.OleDb");
break;
default:
f = GetDbProviderFactory("System.Data.SqlClient");
break;
}
return f;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回数据工厂
/// </summary>
/// <param name="providername"></param>
/// <returns></returns>
public DbProviderFactory GetDbProviderFactory(string providername)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return DbProviderFactories.GetFactory(providername);
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//==============================================CreateConnection=============================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
创建数据库连接 public DbConnection CreateConnection()#region 创建数据库连接 public DbConnection CreateConnection()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建数据库连接
/// </summary>
/// <returns></returns>
public DbConnection CreateConnection()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbConnection con = GetDbProviderFactory().CreateConnection();
con.ConnectionString = GetConnectionString();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return con;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建数据库连接
/// </summary>
/// <param name="provdername"></param>
/// <returns></returns>
public DbConnection CreateConnection(string provdername)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbConnection con = GetDbProviderFactory(provdername).CreateConnection();
con.ConnectionString = GetConnectionString();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return con;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//==============================================CreateCommand================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
创建执行命令对象 public override DbCommand CreateCommand(string sql, CommandType cmdType, DbParameter[] parameters)#region 创建执行命令对象 public override DbCommand CreateCommand(string sql, CommandType cmdType, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建执行命令对象
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdType"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public DbCommand CreateCommand(string sql, CommandType cmdType, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbCommand _command = GetDbProviderFactory().CreateCommand();
_command.Connection = CreateConnection();
_command.CommandText = sql;
_command.CommandType = cmdType;
if (parameters != null && parameters.Length > 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach (DbParameter param in parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Parameters.Add(param);
}
}
return _command;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建执行命令对象
/// </summary>
/// <param name="sql">SQL语句</param>
/// <returns>执行命令对象实例</returns>
public DbCommand CreateCommand(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return CreateCommand(sql, CommandType.Text, parameters);
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建执行命令对象
/// </summary>
/// <param name="sql">SQL语句</param>
/// <returns>执行命令对象实例</returns>
public DbCommand CreateCommand(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return CreateCommand(sql, cmdtype, parameters);
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建执行命令对象
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">参数</param>
/// <returns>执行命令对象实例</returns>
public DbCommand CreateCommand(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return CreateCommand(sql, CommandType.Text, parameters);
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=========================================CreateAdapter()==============================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
创建数据适配器 CreateAdapter(string sql)#region 创建数据适配器 CreateAdapter(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建数据适配器
/// </summary>
/// <param name="sql">SQL,语句</param>
/// <returns>数据适配器实例</returns>
public DbDataAdapter CreateAdapter(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return CreateAdapter(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建数据适配器
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <returns>数据适配器实例</returns>
public DbDataAdapter CreateAdapter(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return CreateAdapter(sql, cmdtype, parameters);
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建数据适配器
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>数据适配器实例</returns>
public DbDataAdapter CreateAdapter(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbConnection _connection = CreateConnection();
DbCommand _command = GetDbProviderFactory().CreateCommand();
_command.Connection = _connection;
_command.CommandText = sql;
_command.CommandType = cmdtype;
if (parameters != null && parameters.Length > 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach (DbParameter _param in parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Parameters.Add(_param);
}
}
DbDataAdapter da = GetDbProviderFactory().CreateDataAdapter();
da.SelectCommand = _command;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return da;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=========================================CreateParameter===================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
生成参数 public override SqlParameter CreateParameter(string field, string dbtype, string value)#region 生成参数 public override SqlParameter CreateParameter(string field, string dbtype, string value)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 创建参数
/// </summary>
/// <param name="field">参数字段</param>
/// <param name="dbtype">参数类型</param>
/// <param name="value">参数值</param>
/// <returns></returns>
public DbParameter CreateParameter(string field, string dbtype, string value)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter p = GetDbProviderFactory().CreateParameter();
p.ParameterName = field;
p.Value = value;
return p;
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//======================================================ExecuteCommand()============================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行非查询语句,并返回受影响的记录行数 ExecuteCommand(string sql)#region 执行非查询语句,并返回受影响的记录行数 ExecuteCommand(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回受影响的记录行数
/// </summary>
/// <param name="sql">SQL语句</param>
/// <returns>受影响记录行数</returns>
public int ExecuteCommand(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return ExecuteCommand(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回受影响的记录行数
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <returns>受影响记录行数</returns>
public int ExecuteCommand(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return ExecuteCommand(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回受影响的记录行数
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">参数</param>
/// <returns>受影响记录行数</returns>
public int ExecuteCommand(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ExecuteCommand(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///批量执行SQL语句
/// </summary>
/// <param name="SqlList">SQL列表</param>
/// <returns></returns>
public bool ExecuteCommand(ArrayList SqlList)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbConnection con = CreateConnection();
con.Open();
bool iserror = false;
string strerror = "";
DbTransaction SqlTran =con.BeginTransaction();
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for (int i = 0; i < SqlList.Count; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DbCommand _command = GetDbProviderFactory().CreateCommand();
_command.Connection = con;
_command.CommandText = SqlList[i].ToString();
_command.Transaction = SqlTran;
_command.ExecuteNonQuery();
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
catch (Exception ex)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
iserror = true;
strerror = ex.Message;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
finally
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (iserror)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SqlTran.Rollback();
throw new Exception(strerror);
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SqlTran.Commit();
}
con.Close();
}
if (iserror)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return false;
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回受影响的记录行数
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>受影响记录行数</returns>
public int ExecuteCommand(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int _result = 0;
DbCommand _command = CreateCommand(sql, cmdtype, parameters);
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Connection.Open();
_result = _command.ExecuteNonQuery();
}
catch (Exception ex)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception(ex.Message);
}
finally
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Connection.Close();
}
return _result;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=====================================================ExecuteScalar()=============================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行非查询语句,并返回首行首列的值 ExecuteScalar(string sql)#region 执行非查询语句,并返回首行首列的值 ExecuteScalar(string sql)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回首行首列的值
/// </summary>
/// <param name="sql">SQL语句</param>
/// <returns>Object</returns>
public object ExecuteScalar(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return ExecuteScalar(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回首行首列的值
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <returns>Object</returns>
public object ExecuteScalar(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return ExecuteScalar(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回首行首列的值
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">参数</param>
/// <returns>Object</returns>
public object ExecuteScalar(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ExecuteScalar(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行非查询语句,并返回首行首列的值
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>Object</returns>
public object ExecuteScalar(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
object _result=null;
DbCommand _command = CreateCommand(sql, cmdtype, parameters);
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Connection.Open();
_result = _command.ExecuteScalar();
}
catch
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw;
}
finally
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Connection.Close();
}
return _result;
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=====================================================ExecuteReader()=============================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行查询,并以DataReader返回结果集 ExecuteReader(string sql)#region 执行查询,并以DataReader返回结果集 ExecuteReader(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataReader返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <returns>IDataReader</returns>
public DbDataReader ExecuteReader(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return ExecuteReader(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataReader返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <returns>IDataReader</returns>
public DbDataReader ExecuteReader(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return ExecuteReader(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataReader返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">参数</param>
/// <returns>IDataReader</returns>
public DbDataReader ExecuteReader(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ExecuteReader(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataReader返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>IDataReader</returns>
public DbDataReader ExecuteReader(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbDataReader _result;
DbCommand _command = CreateCommand(sql, cmdtype, parameters);
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_command.Connection.Open();
_result = _command.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw;
}
finally
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
return _result;
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=====================================================GetDataSet()================================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行查询,并以DataSet返回结果集 GetDataSet(string sql)#region 执行查询,并以DataSet返回结果集 GetDataSet(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataSet返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <returns>DataSet</returns>
public DataSet GetDataSet(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return GetDataSet(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataSet返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <returns>DataSet</returns>
public virtual DataSet GetDataSet(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
return GetDataSet(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataSet返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">参数</param>
/// <returns>DataSet</returns>
public virtual DataSet GetDataSet(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetDataSet(sql, CommandType.Text, parameters);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataSet返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataSet</returns>
public virtual DataSet GetDataSet(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataSet _result = new DataSet();
IDataAdapter _dataAdapter = CreateAdapter(sql, cmdtype, parameters);
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_dataAdapter.Fill(_result);
}
catch
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw;
}
finally
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
return _result;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataSet返回指定记录的结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="StartIndex">开始索引</param>
/// <param name="RecordCount">显示记录</param>
/// <returns>DataSet</returns>
public virtual DataSet GetDataSet(string sql, int StartIndex, int RecordCount)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetDataSet(sql, StartIndex, RecordCount);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=====================================================GetDataView()===============================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行查询,并以DataView返回结果集 GetDataView(string sql)#region 执行查询,并以DataView返回结果集 GetDataView(string sql)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataView返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataView</returns>
public DataView GetDataView(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
DataView dv = GetDataSet(sql, CommandType.Text, parameters).Tables[0].DefaultView;
return dv;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataView返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataView</returns>
public DataView GetDataView(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
DataView dv = GetDataSet(sql, cmdtype, parameters).Tables[0].DefaultView;
return dv;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataView返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataView</returns>
public DataView GetDataView(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DataView dv = GetDataSet(sql, CommandType.Text, parameters).Tables[0].DefaultView;
return dv;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataView返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataView</returns>
public DataView GetDataView(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataView dv = GetDataSet(sql, cmdtype, parameters).Tables[0].DefaultView;
return dv;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataView返回指定记录的结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="StartIndex">开始索引</param>
/// <param name="RecordCount">显示记录</param>
/// <returns>DataView</returns>
public DataView GetDataView(string sql, int StartIndex, int RecordCount)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetDataSet(sql, StartIndex, RecordCount).Tables[0].DefaultView;
}
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//=====================================================GetDataTable()==============================================
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行查询,并以DataTable返回结果集 GetDataTable(string sql)#region 执行查询,并以DataTable返回结果集 GetDataTable(string sql)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataTable返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string sql)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
DataTable dt = GetDataSet(sql, CommandType.Text, parameters).Tables[0];
return dt;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataTable返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string sql, CommandType cmdtype)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DbParameter[] parameters = new DbParameter[0];
DataTable dt = GetDataSet(sql, cmdtype, parameters).Tables[0];
return dt;
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataTable返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string sql, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DataTable dt = GetDataSet(sql, CommandType.Text, parameters).Tables[0];
return dt;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataTable返回结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="cmdtype">命令类型</param>
/// <param name="parameters">参数</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string sql, CommandType cmdtype, DbParameter[] parameters)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataTable dt = GetDataSet(sql, cmdtype, parameters).Tables[0];
return dt;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,并以DataTable返回指定记录的结果集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="StartIndex">开始索引</param>
/// <param name="RecordCount">显示记录</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string sql, int StartIndex, int RecordCount)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetDataSet(sql, StartIndex, RecordCount).Tables[0];
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行查询,返回以空行填充的指定条数记录集
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="SizeCount">显示记录条数</param>
/// <returns>DataTable</returns>
public DataTable GetDataTable(string sql, int SizeCount)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataTable dt = GetDataSet(sql).Tables[0];
int b = SizeCount - dt.Rows.Count;
if (dt.Rows.Count < SizeCount)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for (int i = 0; i < b; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
}
}
return dt;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#endregion
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
转载于:https://www.cnblogs.com/wangzhq/archive/2006/09/14/504309.html