Ibatis 返回datatable数据类型案例

时间:2022-06-30 20:14:37

 

 

/// <summary>
/// 查询实体 [DataSet数据集]
/// </summary>
/// <param name="statementName">原命令名称</param>
/// <param name="paramObject">参数</param>
/// <returns>DataSet数据集</returns>
public virtual DataSet GetDataSetProce(string statementName, object paramObject)
{
ISqlMapper sqlMapper = MapperFactory.Get();
ISqlMapSession sqlMapSession = GetMapSession(sqlMapper);
IMappedStatement mappedStatement = sqlMapper.GetMappedStatement(statementName);
RequestScope requestScope = mappedStatement.Statement.Sql.GetRequestScope(mappedStatement, paramObject, sqlMapSession);
mappedStatement.PreparedCommand.Create(requestScope, sqlMapSession, mappedStatement.Statement, paramObject);
IDbCommand dbCommand = sqlMapSession.CreateCommand(CommandType.StoredProcedure);
IDbCommand interfaceCmd = requestScope.IDbCommand;
dbCommand.CommandTimeout = 0;
dbCommand.CommandText = interfaceCmd.CommandText;
foreach (IDataParameter dataParameter in interfaceCmd.Parameters)
{
IDataParameter sqlParam = new SqlParameter();
sqlParam.ParameterName = dataParameter.ParameterName;
sqlParam.Value = dataParameter.Value;
sqlParam.DbType = dataParameter.DbType;
dbCommand.Parameters.Add(sqlParam);
}
dbCommand.Connection = sqlMapSession.Connection;
interfaceCmd.Connection = sqlMapSession.Connection;
var dbDataAdapter = sqlMapSession.CreateDataAdapter(dbCommand);
var ds = new DataSet();
dbDataAdapter.Fill(ds);
return ds;
}