Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
trying to insert transaction details to a table . when i press save this error message is displayed:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

What I have tried:

private void btnsave_Click(object sender, EventArgs e)
       {
           transaction_getter_setter transaction = new transaction_getter_setter();
           string DeaCustName = txtname.Text;
           DeaCust dc = dcDal.GetDeaCustIDFromName(DeaCustName);
           transaction.Dea_Cust_id = dc.id;
           transaction.total = decimal.Parse(lbltot.Text);
           transaction.transaction_time = DateTime.Now;
           transaction.tax =decimal.Parse( lbltax.Text);
           bool success = false;
           using (TransactionScope scope = new TransactionScope())
           {
               int transactionID = -1;
               bool w = tDAL.Insert_Transaction(transaction, out transactionID);
               success = w;
               if (success == true)
               {
                   MessageBox.Show("Transaction Completed Succesfully");
               }
               else
               {
                   MessageBox.Show("Transaction Failed");
               }
Posted
Updated 29-Jul-20 2:40am

1 solution

Look at the error message, it couldn't be any clearer:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

Somewhere, you are trying to insert either a very, very old date (over 250 years ago!) or a very, very long expiry period (over 8000 years in the future!) to a DATETIME column, and SQL is - quite rightly - saying "don't do that!"

Use the debugger to find exactly what values you are passing to the DB, and then start looking for why the data is so ridiculous.

If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
achalake 29-Jul-20 8:51am    
thank u very much sir!
OriginalGriff 29-Jul-20 9:06am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900