Ibatis返回Dataset和打印sql语句的方法(原创)
来源:互联网 发布:程序员转正申请 编辑:程序博客网 时间:2024/05/21 20:21
using System.Data;
using IBatisNet.DataMapper;
using IBatisNet.DataMapper.MappedStatements;
using IBatisNet.DataMapper.Scope;
namespace DataAccess
{
public class BaseSqlMapDao
{
private ISqlMapper _mapper = null;
public ISqlMapper mapper
{
get
{
if (_mapper == null)
{
_mapper = Mapper.Instance();
}
return _mapper;
}
}
///1.5版本
public static DataSet QueryForDataSet(string statementName, object paramObject)
{
DataSet ds = new DataSet();
ISqlMapper mapper = Mapper.Instance();
IMappedStatement statement = mapper.GetMappedStatement(statementName);
if (!mapper.IsSessionStarted)
{
mapper.OpenConnection();
}
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, mapper.LocalSession);
statement.PreparedCommand.Create(scope, mapper.LocalSession, statement.Statement, paramObject);
mapper.LocalSession.CreateDataAdapter(scope.IDbCommand).Fill(ds);
return ds;
}
///1.6版本
///
/// 返回Dataset的方法
///
///
///
///
public static DataSet QueryForDataSet(string statementName, object paramObject)
{
DataSet ds = new DataSet();
ISqlMapper mapper = Mapper.Instance();
IMappedStatement statement = mapper.GetMappedStatement(statementName);
if (!mapper.IsSessionStarted)
{
mapper.OpenConnection();
}
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, mapper.LocalSession);
statement.PreparedCommand.Create(scope, mapper.LocalSession, statement.Statement, paramObject);
IDbCommand command = mapper.LocalSession.CreateCommand(CommandType.Text);
command.CommandText = scope.IDbCommand.CommandText;
foreach (IDataParameter pa in scope.IDbCommand.Parameters)
{
command.Parameters.Add(new SqlParameter(pa.ParameterName, pa.Value));
}
mapper.LocalSession.CreateDataAdapter(command).Fill(ds);
return ds;
}
public static string GetSql(string statementName, object paramObject)
{
ISqlMapper mapper = Mapper.Instance();
IMappedStatement statement = mapper.GetMappedStatement(statementName);
if (!mapper.IsSessionStarted)
{
mapper.OpenConnection();
}
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, mapper.LocalSession);
return scope.PreparedStatement.PreparedSql;
}
}
}
- Ibatis返回Dataset和打印sql语句的方法(原创)
- ibatis和myBatis打印sql语句的log4j配置文件
- mybatis和ibatis控制台打印sql语句
- ibatis打印sql语句
- ibatis打印sql语句
- ibatis打印sql语句
- 打印出Ibatis最终的SQL语句
- 打印Ibatis最终的SQL语句
- 只打印IBatis的sql语句
- Ibatis 后台打印完整的sql语句
- 打印出Ibatis最终的SQL语句
- 打印出Ibatis最终的SQL语句
- 只打印IBatis的sql语句
- Ibatis 后台打印完整的sql语句
- ibatis 打印sql 方法
- Ibatis打印sql语句--log4j
- ibatis 如何打印SQL语句
- Ibatis后台打印sql语句
- HTML转义字符表
- 字符串过滤
- 一个项目的开发过程及成员组成
- ASP.NET AJAX1.0:Web Service调用
- sqlserver2005 递归查询
- Ibatis返回Dataset和打印sql语句的方法(原创)
- 利用Hashtable实现不准确的在线状态(Session.SessionID)
- C#中HashTable的使用
- sqlserver2005实现oracle中的rownum(记录号)功能
- ASP.NET中GUID类
- javascript 操作cookie类
- sql server 中的as when then 多重选择
- 使用COMPUTE和COMPUTE BY对数据进行汇总
- sql server 2005中的except和INTERSECT运算(附加Compute by子句)