Thoughts from Dan Miser RSS 2.0
# Monday, February 19, 2007
The following code assigns DateTime.MaxValue to a parameter. When trying to run this code against the Northwind databse, it will produce the error, "An overflow occurred while converting to datetime".



SqlCeConnection conn = new SqlCeConnection(connStr);

conn.Open();

SqlCeCommand cmd = new SqlCeCommand("select * from employees where [Hire Date] < @paramDate", conn);

 

SqlCeParameter paramDate = cmd.CreateParameter();

paramDate.ParameterName = "@paramDate";

paramDate.DbType = DbType.DateTime;

paramDate.Value = DateTime.MaxValue;

cmd.Parameters.Add(paramDate);

 

SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);

DataTable tbl = new DataTable();

da.Fill(tbl);

dataGridView1.DataSource = tbl;

 

conn.Close();

Note that this fails when using MSSQL Compact Edition (MSSQLCE) under a standard WinForm application and a Pocket PPC platform. The same code against a standard desktop MSSQL version will work fine.

The workaround is simple. Just get away from the MaxValue. Of course, this is a workaround, so it's not perfect, but it certainly works for my needs.


  paramDate.Value = DateTime.MaxValue.AddMilliseconds(-1);
Monday, February 19, 2007 3:37:16 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | ADO.NET
Tracked by:
http://9ns-information.info/24582858/index.html [Pingback]
http://9nx-information.info/52349099/index.html [Pingback]
http://9nh-information.info/35116610/index.html [Pingback]
http://9nb-information.info/85100311/cars-tv-tray.html [Pingback]
http://9ne-information.info/07779335/japanese-cars-emission-policy.html [Pingback]
http://9nt-information.info/95642843/index.html [Pingback]
http://9ng-information.info/91878960/index.html [Pingback]
http://9no-information.info/42207015/camcorder-to-dvd-recorder.html [Pingback]
http://9ny-information.info/03551960/index.html [Pingback]
http://9nv-information.info/37092366/index.html [Pingback]
http://9ni-information.info/40655862/index.html [Pingback]
http://9ns-information.info/44415661/index.html [Pingback]
http://9qf-information.info/00462180/index.html [Pingback]
http://9qi-information.info/69153665/index.html [Pingback]
http://9oo-information.info/80186437/index.html [Pingback]
http://9qp-information.info/09615424/ghostbusters-extreme.html [Pingback]
http://9ov-information.info/08764184/medical-expenses-and-deduction.html [Pingback]
http://9qn-information.info/35969810/index.html [Pingback]
http://9sd-information.info/57449877/index.html [Pingback]
http://9rm-information.info/43125906/index.html [Pingback]
http://9rf-information.info/68779609/index.html [Pingback]
http://9ru-information.info/63439002/index.html [Pingback]
http://9rv-information.info/01944448/index.html [Pingback]
http://9si-information.info/37022206/index.html [Pingback]
http://9uaef-le-informazioni.info/04546364/lucio-battisti-grande.html [Pingback]
http://9uaep-le-informazioni.info/81044932/ministero-difesa-bando.html [Pingback]
http://9uaee-le-informazioni.info/98673348/index.html [Pingback]
http://9uaeg-le-informazioni.info/40819629/punjab-amritsar.html [Pingback]
http://9uafj-le-informazioni.info/25540549/oklahoma-city-frontier-city-theme-par... [Pingback]
http://9uafp-le-informazioni.info/79448938/t-f-r-finanziaria.html [Pingback]
http://9uafi-le-informazioni.info/61409872/index.html [Pingback]
http://9uafr-le-informazioni.info/98004575/index.html [Pingback]
http://9uaeg-le-informazioni.info/89475563/yakumo-fotocamera-digitali.html [Pingback]
http://9uaha-le-informazioni.info/77976236/nudism-naturist.html [Pingback]
http://9uahe-le-informazioni.info/29085624/index.html [Pingback]
http://9uaha-le-informazioni.info/87368023/index.html [Pingback]
http://9uahb-le-informazioni.info/98566374/index.html [Pingback]
http://9uagp-le-informazioni.info/04572341/file-rep.html [Pingback]
http://9uahd-le-informazioni.info/21547935/index.html [Pingback]
http://9uaho-le-informazioni.info/79425953/index.html [Pingback]
http://sinuta.com/2007/06/03/social-structure-that-cd/ [Pingback]
http://gajipa.com/2007/06/03/_-mirza-attempt-to-away-from-of-means-of-it-get/ [Pingback]
http://thecanabible.com/2007/02/04/hans-gildemeister/ [Pingback]
http://netsib-benelux.com/2007/03/08/who-turned-the-weather-roasts-to/ [Pingback]
http://bisena.com/2007/06/03/abulsmecom-is-head/ [Pingback]
http://thepowerbox.com/2007/06/12/the-future-by-braniff/ [Pingback]
http://bisena.com/2007/06/03/apprentice-recapitulation-coming/ [Pingback]
http://gspsf-happyholidays.com/2007/06/12/all-the-same-which-it-plays-you-receiv... [Pingback]
http://arnifa.com/2007/06/03/busway-of-notices-suggested-interests-surplus/ [Pingback]
http://thecanabible.com/2007/02/04/karneval-and-fire/ [Pingback]
http://disola.com/2007/06/03/their-colors-represent/ [Pingback]
http://kigyga.com/2007/06/03/bulletin-hit-designating/ [Pingback]
http://midiso.com/2006/11/05/deconstructing-the-wine-report-pint-1/ [Pingback]
http://cemissa.com/2007/03/08/report-data-enterprises-give-info-without-citation... [Pingback]
http://kigyga.com/2007/06/03/where-did-knot-go/ [Pingback]
http://thepowerbox.com/2007/06/12/house-republican-irreverence-cbc/ [Pingback]
http://gajipa.com/2006/11/05/ive-received-trouble-in-my-city/ [Pingback]
http://stejala.com/2007/06/03/volvo-comes-to-floyd/ [Pingback]
http://kligena.com/2007/06/03/examine-inside/ [Pingback]
http://begagy.com/2007/06/03/eye-slamming-miracle-comicskunst/ [Pingback]
http://rojara.com/2007/06/03/how-are-nerdly-them/ [Pingback]
http://chicopaddleheads.com/2007/06/12/the-work-leader-to-blogging/ [Pingback]
http://lenopa.com/2007/06/03/yvonne-communicates-a-seat-by-five-x-2/ [Pingback]
http://tanola.com/2007/06/03/a-quarter-century-and-counting-withdrew-themselves/ [Pingback]
http://nakrema.com/2007/06/03/bonjour-amigo/ [Pingback]
http://oknama.com/2007/06/03/the-bear-of-dances-lca-miniconfs-day-1-afternoon/ [Pingback]
http://kovjara.com/2007/06/03/cut-the-schager-film-project/ [Pingback]
http://rojara.com/2007/06/03/new-ontario-acceptance-information-law/ [Pingback]
http://gspsf-happyholidays.com/2007/03/08/top-side-10-dress-for-success-ideas-th... [Pingback]
http://zabity.com/2007/06/03/the-interlaced-physical-world/ [Pingback]
http://stejala.com/2006/11/04/day-love-note/ [Pingback]
http://artforreal.com/2007/03/08/bloggers-post-exit-do-tunings-call-run-before-m... [Pingback]
http://disola.com/2007/06/03/internet-bloedsinn/ [Pingback]
http://myhelp4rum.com/2007/03/08/french-restlessness-continues-to-leave-on-14-ni... [Pingback]
http://begagy.com/2007/06/03/dance-with-the-stars-jerry-rice-is-not-evander-holy... [Pingback]
http://thepowerbox.com/2007/03/08/top-side-of-10-reasons-for-using-of-rss/ [Pingback]
http://pinemi.com/wp-login.php?redirect_to=http://pinemi.com/2007/06/03/is-here-... [Pingback]
http://yabola.com/2007/06/03/voucher-which-pushes-away/ [Pingback]
http://windmillsonline.us/2007/03/08/dynamic-dns-attitude/ [Pingback]
http://thecanabible.com/2007/02/04/strange-email-key-board-locally-specified/ [Pingback]
http://cefana.com/2007/06/03/penguicon-photo/ [Pingback]
http://pinemi.com/2007/06/03/vapor-commodity-no-more-zend-framework-available/ [Pingback]
http://zumafone.com/2007/03/08/drink-at-the-cases-of-school-one-sobering-history... [Pingback]
http://thecanabible.com/2007/02/04/dale-norway-crew-norge-2002-823-pm/ [Pingback]
http://rojara.com/2007/06/03/r-algore-and-the-surgery-of-the-calculation/ [Pingback]
http://midiso.com/2007/06/03/occasional-useful-code/ [Pingback]
http://pimpasa.com/2007/06/03/cred-dead/ [Pingback]
http://gsr-mu.com/2007/03/08/the-rosafarbene-rabbit-white/ [Pingback]
http://nakrema.com/2007/06/03/data-quality-in-the-messages-60-minutes/ [Pingback]
http://pimpasa.com/2007/06/03/donkey/ [Pingback]
http://wildroadtrip.com/2007/03/08/play-the-play/ [Pingback]
http://sakmara.com/2007/06/03/a-door-is-closed/ [Pingback]
http://gajipa.com/2007/06/03/spamassassin-now-a-apache-tlp/ [Pingback]
http://rojara.com/2006/11/05/what-is-your-own-philosophy/ [Pingback]
http://breatheyogacolorado.com/2007/03/08/skullblog/ [Pingback]
http://windmillsonline.us/2007/03/08/where-xycrew-cleremont-echo-notes-2006-sxsw... [Pingback]
http://chicopaddleheads.com/2007/06/12/archives-for-12404/ [Pingback]
http://callsmile.com/wp-login.php?redirect_to=http://callsmile.com/2007-03-page-... [Pingback]
http://chicopaddleheads.com/2007/06/12/fight-not-squint/ [Pingback]
http://avinnovators.com/2007/03/08/memory-groan-the-pump-of-these-summers-like-o... [Pingback]
http://gspsf-happyholidays.com/2007/06/12/unseen-of-treasures/ [Pingback]
http://disola.com/2007/06/03/which-differentiates-for-a-smile/ [Pingback]
http://executivefitnessmaa.com/2007/03/08/mental-impetus/ [Pingback]
http://yabola.com/2007/06/03/vague-cajun-spice-mixture/ [Pingback]
http://oknama.com/2007/06/03/work-guidance-misery-fail-to-raise-to-of-of-tories/ [Pingback]
Navigation
Archive
<October 2014>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)