Good afternoon everyone. I have a giant need to get things done.
I have an object DataTable
with the result with column "ID_CLIENTE"
.
I have an object Cliente
with the property ID_CLIENTE
.
Is there any way to populate the Cliente
object with the DataTable
data automatically, just passing the type of the Cliente
object and it knows that the "ID_CLIENTE"
column of DataTable
has to be bound in the property "ID_CLIENTE"
of object Cliente
?
Could I be clear?
Client Class
public class Cliente
{
public int ID_CLIENTE { get; set; }
public string NOME_CLIENTE { get; set; }
public DateTime DT_NASC_CLIENTE { get; set; }
}
Loading DataTable
SqlConnection conexao = new SqlConnection("STRING_CONEXAO");
SqlCommand comando = new SqlCommand("SELECT * FROM TAB_CLIENTE", conexao);
DataTable dt = new DataTable();
try
{
conexao.Open();
dt.Load(comando.ExecuteReader());
conexao.Close();
}
catch (Exception)
{
if (conexao.State != ConnectionState.Closed)
conexao.Close();
throw;
}