Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime.Now into SmallDateTime field exception error.

Status
Not open for further replies.

xavstone

Technical User
Apr 12, 2005
33
GB
Hi guys,

Im an asp.net c# newbie, and this is my first post, so i hope im submitting it in the right place (not sure whther it should be here or SQL. Anyway, hopefully this will be an easy one for someone.

Im trying to get a date into an SQL smalldatetime column using:

AddArt.InsertParameters.Add("dateinserted", DateTime.Now.ToString());

but all all i keep getting is:

Arithmetic overflow error converting expression to data type smalldatetime. The statement has been terminated.

i also tried this:

AddArt.InsertParameters.Add("dateinserted", DateTime.Now.ToShortDateString());

Thanks in advance for any suggestions.

Ben
 
What happens if you just use "DateTime.Now"?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi thanks,

If you mean like this:

AddArt.InsertParameters.Add("dateinserted", DateTime.Now);

I get this:

Compiler Error Message: CS1502: The best overloaded method match for System.Web.UI.WebControls.ParameterCollection.Add(string, string)' has some invalid arguments
 
ok i changed the line to this:

AddArt.InsertParameters.Add("dateinserted", DateTime.Now.ToLongDateString());

which worked in that it entered the date in the field as "24/10/2006 00:00:00" but its not midnight here :/

Can anyone explain this?
 
OK, if the Add method of whatever control you are using will only accept a string, you may have to format the date into a string that your database will understand e.g System.DateTime.Today.ToString("yyyy-MM-dd")


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
thanks again ca8msm.

I put changed the in line query into a stored procedure and it just started working, i have no idea why but im beyond caring now.

I think the time being 00:00:00 has something to do wiith SQL rounding dates with no explicit time format. If i ever figure it work it out i will post it here.

thanks again.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top