1
Good afternoon everyone. I have a huge need to be able to put together a situation.
I have an object DataTable with the result with the column "ID_CLIENTE".
I have an object Cliente with the property ID_CLIENTE.
Is there any way to fill the object Cliente with the data of DataTable automatically, just passing the object type Cliente and he knows that the column "ID_CLIENTE" of DataTable must be linked to the property "ID_CLIENTE" of the object Cliente ?
I made myself 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;
}
How do you carry the
Datatable? and how is this Customer class, can provide all the code of this class?– novic
@Virgilionovic I changed the question with the data you requested.
– Thiago Henrique
Dude, what you need is an ORM (like Entity Framework).
– Intruso
You want the conversion of a
DataTablein aClassor can propose an ideal solution?– novic
I would like the conversion of
DataTableinClass, but I agree to propose the solution yes, of course.– Thiago Henrique