Hey Guys,
I was wondering could someone point me in the right direction.
Getting an error: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

What my code is doing is checking for the earliest date in one table(tblBookedTimes) and assigning this to earlydatestart.

Then I want to update table Galway_storage with this variable.
But I keep getting the error despite both fields in both tables being type smalldatetime.

Heres the code.

msdb247TableAdapters.tblBookedTimesTableAdapter BookedTimesAdapter = new msdb247TableAdapters.tblBookedTimesTableAdapter();
msdb247.tblBookedTimesDataTable BookedTimes = BookedTimesAdapter.GetData();

foreach (msdb247.tblBookedTimesRow tblBookedTimes in BookedTimes)
{
    if (tblBookedTimes.CellID == cellid && tblBookedTimes.warehouse == warehouseid)
                {
                    if (earlydatestart < tblBookedTimes.Booked_Start && tblBookedTimes.Booked_Start != null)//to display the earliest date and its end date in the gui
                    {
                       [B]earlydatestart =Convert.ToDateTime(tblBookedTimes.Booked_Start);[/B]
                            earlydateend = Convert.ToDateTime(tblBookedTimes.Booked_End);

                    }
              }
}

msdb247TableAdapters.Galway_storageTableAdapter Galway_storageAdapter = new msdb247TableAdapters.Galway_storageTableAdapter();
msdb247.Galway_storageDataTable Galway_storagead = Galway_storageAdapter.GetData();

foreach (msdb247.Galway_storageRow Galway_storage in Galway_storagead)
{
   if (Galway_storage.CellID == cellid && Galway_storage.warehouse == warehouseid)
    {
         [B]Galway_storage.Booked_Start = earlydatestart;[/B]
         Galway_storage.Boooked_end = earlydateend;
         Galway_storage.Item_ID = itemid;
         fullbool = Galway_storage.Full_Bool;
         Galway_storage.Booked = booked;
         Galway_storage.Full_Bool = fullbool;

      }
}

Galway_storageAdapter.Update(Galway_storagead);

This has been wrecking my head for the last hour so any help would be greatly appreciated!
Thanks!!

Edited 3 Years Ago by Reverend Jim: Fixed formatting

hey figured a work around myself where i converted it to a string and then converted it back again when i wanted to insert into the database.
thanks

Why not just get the minimum date from the database instead of iterating through it in code.
use the Min() aggregate to pull it out.

This article has been dead for over six months. Start a new discussion instead.