In the following code, I have manually assigned the values of each column to variables. Is there a shorter code that can do this for me without having to type each column's name, and manually assigning them to individual variables?
while (rdr.Read())
{
var book = new BookViewModel();
book.ship_last_name = rdr["ship_last_name"].ToString();
book.ship_first_name = rdr["ship_first_name"].ToString();
book.ship_zip = rdr["ship_zip"].ToString();
book.ship_state = rdr["ship_state"].ToString();
book.ship_address = rdr["ship_address"].ToString();
book.ship_city = rdr["ship_city"].ToString();
book.day_phone = rdr["day_phone"].ToString();
book.email_address = rdr["email_address"].ToString();
model.Add(book);
}
Also, if possible, can I add if statements in there to check if that particular column in a given row is null or not? Not just for null, but any other conditions.
Thanks in advance. :)