Please, i can convert this method to uses Dapper?
public DataTable GetLeituras ( int ultimas )
{
DataTable listaLeiturasRomaneio = new DataTable();
try
{
_sqlConnection.Open();
_sqlCommand = new SqlCommand();
_sqlCommand.Connection = _sqlConnection;
_sqlCommand.CommandText = "BuscarUltimasLeituras";
_sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
_sqlCommand.Parameters.Add("@Last", SqlDbType.Int).Value = ultimas;
_sqlAdapter = new SqlDataAdapter(_sqlCommand);
_sqlAdapter.Fill(listaLeiturasRomaneio);
}
catch ( SqlException )
{
listaLeiturasRomaneio = null;
}
finally
{
_sqlConnection.Close();
}
return listaLeiturasRomaneio;
}
If you still want a DataTable
, you could try:
var listaLeiturasRomaneio = new DataTable();
using (var reader = _sqlConnection.ExecuteReader(
"BuscarUltimasLeituras", new { Last = ultimas },
commandType: CommandType.StoredProcedure))
{
listaLeiturasRomaneio.Load(reader);
}
However, the more typical usage would be to create a class
to match your data, then:
var listaLeiturasRomaneio = _sqlConnection.Query<YourType>(
"BuscarUltimasLeituras", new { Last = ultimas },
commandType: CommandType.StoredProcedure).AsList();
Note that dapper also supports dynamic
usage, but this is usually for casual usage:
var listaLeiturasRomaneio = _sqlConnection.Query(
"BuscarUltimasLeituras", new { Last = ultimas },
commandType: CommandType.StoredProcedure).AsList();