参考好多前人的东东后 整理的。
今天看了论坛关于分层结构的讨论,决定共享下我的部分代码。
using
System;
using System.Data;
using System.Data.OleDb;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// AccessHelper 的摘要说明。
/// </summary>
public abstract class AccessHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, CommandType cmdType, string cmdText, OleDbParameter[] cmdParms)
...{
if (conn.State == ConnectionState.Closed)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (OleDbParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
//OleDbTransaction Tran=conn.BeginTransaction();
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
//Tran.Commit();
return val;
}
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OleDbTransaction trans, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读OleDbData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>OleDbDataReader</returns>
public static OleDbDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
OleDbConnection conn = new OleDbConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读OleDbData(记得关闭OleDbDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>OleDbDataReader</returns>
public static OleDbDataReader ExecuteReader(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static OleDbDataReader ExecuteReader(OleDbTransaction trans, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
OleDbDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbTransaction trans, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"AccessData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"AccessData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"AccessData");
return _DataSet;
}
#endregion
}
}
using System.Data;
using System.Data.OleDb;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// AccessHelper 的摘要说明。
/// </summary>
public abstract class AccessHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, CommandType cmdType, string cmdText, OleDbParameter[] cmdParms)
...{
if (conn.State == ConnectionState.Closed)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (OleDbParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
//OleDbTransaction Tran=conn.BeginTransaction();
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
//Tran.Commit();
return val;
}
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OleDbTransaction trans, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读OleDbData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>OleDbDataReader</returns>
public static OleDbDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
OleDbConnection conn = new OleDbConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读OleDbData(记得关闭OleDbDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>OleDbDataReader</returns>
public static OleDbDataReader ExecuteReader(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的OleDb命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>受影响的行数</returns>
public static OleDbDataReader ExecuteReader(OleDbTransaction trans, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
OleDbDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbConnection conn, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbTransaction trans, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
using (OleDbConnection conn = new OleDbConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"AccessData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"AccessData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OleDbString</param>
/// <param name="cmdParms">OleDb参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OleDbTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OleDbParameter[] cmdParms)
...{
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OleDbDataAdapter _DataAdapter = new OleDbDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"AccessData");
return _DataSet;
}
#endregion
}
}
using
System;
using System.Data;
using System.Data.Odbc;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// FoxProHelper 的摘要说明。
/// </summary>
public abstract class FoxProHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(OdbcCommand cmd, OdbcConnection conn, OdbcTransaction trans, CommandType cmdType, string cmdText, OdbcParameter[] cmdParms)
...{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (OdbcParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OdbcTransaction trans, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读OdbcData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>OdbcDataReader</returns>
public static OdbcDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
OdbcConnection conn = new OdbcConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读OdbcData(记得关闭OdbcDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>OdbcDataReader</returns>
public static OdbcDataReader ExecuteReader(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static OdbcDataReader ExecuteReader(OdbcTransaction trans, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
OdbcDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcTransaction trans, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"FoxProData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"FoxProData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"FoxProData");
return _DataSet;
}
#endregion
}
}
using System.Data;
using System.Data.Odbc;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// FoxProHelper 的摘要说明。
/// </summary>
public abstract class FoxProHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(OdbcCommand cmd, OdbcConnection conn, OdbcTransaction trans, CommandType cmdType, string cmdText, OdbcParameter[] cmdParms)
...{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (OdbcParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OdbcTransaction trans, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读OdbcData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>OdbcDataReader</returns>
public static OdbcDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
OdbcConnection conn = new OdbcConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读OdbcData(记得关闭OdbcDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>OdbcDataReader</returns>
public static OdbcDataReader ExecuteReader(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的Odbc命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>受影响的行数</returns>
public static OdbcDataReader ExecuteReader(OdbcTransaction trans, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
OdbcDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcConnection conn, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcTransaction trans, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
using (OdbcConnection conn = new OdbcConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"FoxProData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"FoxProData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">OdbcString</param>
/// <param name="cmdParms">Odbc参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OdbcTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OdbcParameter[] cmdParms)
...{
OdbcCommand cmd = new OdbcCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OdbcDataAdapter _DataAdapter = new OdbcDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"FoxProData");
return _DataSet;
}
#endregion
}
}
using
System;
using System.Data.OracleClient;
using System.Data;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// OracleHelper 的摘要说明。
/// </summary>
public abstract class OracleHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(OracleCommand cmd, OracleConnection conn, OracleTransaction trans, CommandType cmdType, string cmdText, OracleParameter[] cmdParms)
...{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (OracleParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读SQLData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>OracleDataReader</returns>
public static OracleDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
OracleConnection conn = new OracleConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读SQLData(记得关闭OracleDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>OracleDataReader</returns>
public static OracleDataReader ExecuteReader(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static OracleDataReader ExecuteReader(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
OracleDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
#endregion
}
}
using System.Data.OracleClient;
using System.Data;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// OracleHelper 的摘要说明。
/// </summary>
public abstract class OracleHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(OracleCommand cmd, OracleConnection conn, OracleTransaction trans, CommandType cmdType, string cmdText, OracleParameter[] cmdParms)
...{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (OracleParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读SQLData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>OracleDataReader</returns>
public static OracleDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
OracleConnection conn = new OracleConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读SQLData(记得关闭OracleDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>OracleDataReader</returns>
public static OracleDataReader ExecuteReader(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static OracleDataReader ExecuteReader(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
OracleDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleConnection conn, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
using (OracleConnection conn = new OracleConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(OracleTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
...{
OracleCommand cmd = new OracleCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
OracleDataAdapter _DataAdapter = new OracleDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
#endregion
}
}
using
System;
using System.Data.SqlClient;
using System.Data;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// SQLSeverHelper 的摘要说明。
/// </summary>
public abstract class SQLServerHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
...{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (SqlParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读SQLData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读SQLData(记得关闭SqlDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader ExecuteReader(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static SqlDataReader ExecuteReader(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
#endregion
}
}
using System.Data.SqlClient;
using System.Data;
namespace WinSpace.WebLibrary.Data
... {
/**//// <summary>
/// SQLSeverHelper 的摘要说明。
/// </summary>
public abstract class SQLServerHelper
...{
PrepareCommand#region PrepareCommand
/**//// <summary>
///
/// </summary>
/// <param name="cmd"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
/// <param name="cmdType"></param>
/// <param name="cmdText"></param>
/// <param name="cmdParms"></param>
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
...{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
...{
foreach (SqlParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
#endregion
ExecuteNonQuery#region ExecuteNonQuery
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
#endregion
ExecuteReader#region ExecuteReader
/**//// <summary>
/// 获取只读SQLData
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connString);
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 获取只读SQLData(记得关闭SqlDataReader)
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>SqlDataReader</returns>
public static SqlDataReader ExecuteReader(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
try
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
conn.Close();
throw;
}
}
/**//// <summary>
/// 执行不返回结果的SQL命令
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>受影响的行数</returns>
public static SqlDataReader ExecuteReader(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
try
...{
PrepareCommand(cmd, trans.Connection, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
catch
...{
trans.Rollback();
trans.Connection.Close();
throw;
}
}
#endregion
ExecuteScalar#region ExecuteScalar
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/**//// <summary>
/// 获取查询的第1行、第1列的信息
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>object</returns>
public static object ExecuteScalar(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
#endregion
FillDataSet#region FillDataSet
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet);
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="connString">数据库连接字符串</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(string connString,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString))
...{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="conn">数据库连接</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlConnection conn,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
/**//// <summary>
/// 填充记录集
/// </summary>
/// <param name="trans">数据库事务</param>
/// <param name="startRecord">开始的记录数</param>
/// <param name="maxRecords">检索的最大记录个数</param>
/// <param name="cmdType">命令字符串的类型(CommandType)</param>
/// <param name="cmdText">SQLString</param>
/// <param name="cmdParms">SQL参数</param>
/// <returns>DataSet</returns>
public static DataSet FillDataSet(SqlTransaction trans,int startRecord ,int maxRecords, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
...{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
SqlDataAdapter _DataAdapter = new SqlDataAdapter(cmd);
DataSet _DataSet = new DataSet();
_DataAdapter.Fill(_DataSet,startRecord,maxRecords,"SQLServerData");
return _DataSet;
}
#endregion
}
}