Sql row to class
I don't use databases much in my work but I now have a situation that requires it.
In order to have the most flexible way to deal with the info stored in each row of the database I want to convert each row to an instance of a class.
I have to problems with that.
1) I cant seem to get the length of array because I cannot get the rows records effected before I start looping though them.
2) Having to play around with the variables to get them to a usable form is a pain.
Is there an easier way to do this??
Vikrant MorePosted May 18, 2012, 12:59 PM
you need to create the class having variables name same with the name of table column with get and set property,
say suppose i have employee table having column id int and empName varchar(100)
so i will create the following class,
public class Employee
{
public int id {get; set;}
public string empname {get;set;}
}
now you need to create the list of class employee
public list
and asign the records you got from the dataset/datatable and asign it to emp object.