You should give up all of these, and not blindly use ToString():
date_ofbirth = (DateTime) dr["dateofbirth"];
"unbox" .
, ORM -ORM (, "dapper" ) - :
var user = connection.Query<User>("select * from Users where Id=@id",
new {id = 123}).First(); // (this is using "dapper")
User - , , ..
public class User {
public string Surname {get;set;}
...
public DateTime DateOfBirth {get;set;}
}
; , using , ..
using(SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.Read()) {...etc...}
}
.., Dispose() d, . "init null, set to null at the end" , - : p