I have the following class:
public class Invoice
{
public int ID {get; set;}
public DateTime creationDate {get; set;}
}
I have invoices saved in my SQL-Server DB with the following properties:
invoice
- invoiceID [int, null]
- creationDate [datetime, null]
My dates contain the following format: 2018-07-31 00:00:00.000
However, when I get an invoice with the following
SqlCommand command = new SqlCommand(@"SELECT id, creationDate FROM invoice WHERE invoiceID = @invoiceID", conn);
command.Parameters.Add("@InvoiceID", SqlDbType.Int).Value = InvoiceID;
{
conn.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
temp.ID = int.Parse(reader["id"].ToString());
temp.InvoiceDate = Convert.ToDateTime(reader["creationDate"]).ToString("yyyy/MM/dd");
}
conn.Close();
}
However, when i run my code, I get the error:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
What am I doing wrong?