Click here to Skip to main content
15,918,041 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionSyntax question Pin
nlarson1127-Apr-11 4:01
nlarson1127-Apr-11 4:01 
AnswerRe: Syntax question Pin
_Erik_27-Apr-11 4:16
_Erik_27-Apr-11 4:16 
GeneralRe: Syntax question Pin
nlarson1127-Apr-11 4:32
nlarson1127-Apr-11 4:32 
GeneralRe: Syntax question Pin
nlarson1127-Apr-11 15:07
nlarson1127-Apr-11 15:07 
GeneralRe: Syntax question Pin
_Erik_28-Apr-11 1:31
_Erik_28-Apr-11 1:31 
GeneralRe: Syntax question Pin
nlarson1128-Apr-11 3:48
nlarson1128-Apr-11 3:48 
AnswerRe: Syntax question Pin
Jason Vetter27-Apr-11 4:22
Jason Vetter27-Apr-11 4:22 
QuestionTree View Pin
vijay248227-Apr-11 1:40
vijay248227-Apr-11 1:40 
AnswerRe: Tree View Pin
Johan Hakkesteegt28-Apr-11 2:59
Johan Hakkesteegt28-Apr-11 2:59 
QuestionHelp section inside a small app.. Pin
waner michaud26-Apr-11 8:47
waner michaud26-Apr-11 8:47 
AnswerRe: Help section inside a small app.. Pin
Tarakeshwar Reddy26-Apr-11 9:27
professionalTarakeshwar Reddy26-Apr-11 9:27 
GeneralRe: Help section inside a small app.. Pin
waner michaud26-Apr-11 9:53
waner michaud26-Apr-11 9:53 
AnswerRe: Help section inside a small app.. Pin
Tarakeshwar Reddy26-Apr-11 10:15
professionalTarakeshwar Reddy26-Apr-11 10:15 
QuestionSearching in Database between 2 dates. Pin
Kurdy8626-Apr-11 3:46
Kurdy8626-Apr-11 3:46 
AnswerRe: Searching in Database between 2 dates. Pin
Dave Kreskowiak26-Apr-11 4:08
mveDave Kreskowiak26-Apr-11 4:08 
GeneralRe: Searching in Database between 2 dates. Pin
Kurdy8626-Apr-11 4:23
Kurdy8626-Apr-11 4:23 
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 

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.