Click here to Skip to main content
15,887,368 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Searching in Database between 2 dates. Pin
Dave Kreskowiak26-Apr-11 4:53
mveDave Kreskowiak26-Apr-11 4:53 
AnswerRe: Searching in Database between 2 dates. [modified] Pin
Luc Pattyn26-Apr-11 4:13
sitebuilderLuc Pattyn26-Apr-11 4:13 
GeneralRe: Searching in Database between 2 dates. Pin
Kurdy8626-Apr-11 4:26
Kurdy8626-Apr-11 4:26 
GeneralRe: Searching in Database between 2 dates. Pin
Kurdy8627-Apr-11 2:10
Kurdy8627-Apr-11 2:10 
AnswerRe: Searching in Database between 2 dates. Pin
Eddy Vluggen26-Apr-11 4:50
professionalEddy Vluggen26-Apr-11 4:50 
AnswerRe: Searching in Database between 2 dates. Pin
Tim Carmichael26-Apr-11 5:10
Tim Carmichael26-Apr-11 5:10 
AnswerRe: Searching in Database between 2 dates. Pin
Kurdy8627-Apr-11 2:05
Kurdy8627-Apr-11 2:05 
AnswerRe: Searching in Database between 2 dates. [modified] Pin
Luc Pattyn27-Apr-11 2:50
sitebuilderLuc Pattyn27-Apr-11 2:50 
Your code has improved already, however IMO OleDbCommand.Parameters.Add isn't strongly typed, all it does is add strings to some collection.

Not absolutely sure what exactly goes wrong, however my best guess is this:
"26-4-2011' is recognized as "dd-MM-yyyy" and works fine (it does not fit "MM-dd-yyyy"), however "1-5-2011" is recognized as "MM-dd-yyyy", which takes precedence over "dd-MM-yyyy". Regional settings are fooling you.

My suggestion was and is:
- first capture the user data, and turn it into variables of appropriate type; that implies validation;
- then use those variables when adding parameters.

Could look like:
bool allOK=true;
DateTime startDate=DateTime.MinValue;
if (!DateTime.TryParse(tbStartdate.Text, "dd-MM-yyyy', null, out startDate)) {
    allOK=false;
    log("startDate is not valid, should be dd-MM-yyyy format");
}
...
if (allOK) {
    // construct and execute SQL query
}


Note: by explicitly specifying the format, you get independent of the system settings (if that is what you want, your users might want to be in charge).

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Wednesday, April 27, 2011 9:23 AM

GeneralRe: Searching in Database between 2 dates. Pin
Kurdy8627-Apr-11 23:34
Kurdy8627-Apr-11 23:34 
Questionsuperscript Pin
M.Kol25-Apr-11 10:58
M.Kol25-Apr-11 10:58 
AnswerRe: superscript Pin
thatraja26-Apr-11 5:41
professionalthatraja26-Apr-11 5:41 
GeneralRe: superscript Pin
M.Kol27-Apr-11 12:41
M.Kol27-Apr-11 12:41 
QuestionDrawin line graph in VB6 by using a picture box? Pin
Dino-ETF24-Apr-11 3:30
Dino-ETF24-Apr-11 3:30 
AnswerRe: Drawin line graph in VB6 by using a picture box? Pin
thatraja24-Apr-11 18:24
professionalthatraja24-Apr-11 18:24 
Questionpassing parameter to run method at msscriptcontrol Pin
aphei22-Apr-11 17:09
aphei22-Apr-11 17:09 
AnswerRe: passing parameter to run method at msscriptcontrol Pin
Eddy Vluggen23-Apr-11 2:18
professionalEddy Vluggen23-Apr-11 2:18 
GeneralRe: passing parameter to run method at msscriptcontrol Pin
aphei24-Apr-11 15:39
aphei24-Apr-11 15:39 
GeneralRe: passing parameter to run method at msscriptcontrol Pin
Eddy Vluggen25-Apr-11 0:07
professionalEddy Vluggen25-Apr-11 0:07 
QuestionHow to determine what in application causes UAC to be trigger in Windows 7 SP 1? Pin
Jon_Boy22-Apr-11 4:55
Jon_Boy22-Apr-11 4:55 
AnswerRe: How to determine what in application causes UAC to be trigger in Windows 7 SP 1? Pin
Dave Kreskowiak22-Apr-11 6:32
mveDave Kreskowiak22-Apr-11 6:32 
GeneralRe: How to determine what in application causes UAC to be trigger in Windows 7 SP 1? Pin
Jon_Boy26-Apr-11 8:54
Jon_Boy26-Apr-11 8:54 
GeneralRe: How to determine what in application causes UAC to be trigger in Windows 7 SP 1? Pin
Dave Kreskowiak26-Apr-11 10:42
mveDave Kreskowiak26-Apr-11 10:42 
Questioncheck application compatibility for windows 7 Pin
Satish Poojari21-Apr-11 1:47
Satish Poojari21-Apr-11 1:47 
AnswerRe: check application compatibility for windows 7 Pin
Richard MacCutchan21-Apr-11 2:46
mveRichard MacCutchan21-Apr-11 2:46 
AnswerRe: check application compatibility for windows 7 Pin
Dave Kreskowiak21-Apr-11 5:39
mveDave Kreskowiak21-Apr-11 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.