Solved

why am I getting too many items in dataset

Posted on 2014-02-06
5
155 Views
Last Modified: 2014-02-07
sqlstring2 = "Select * from EmployeeAccumInfo where (WORKDATE >  '" & dateString & " ' and WORKDATE < '" & datestring2 & "') ORDER BY ID ASC    "
                Dim Dad As OleDbDataAdapter = New OleDbDataAdapter(sqlstring2, Con)
                Con.Open()
                Dim Dst3 As DataSet = New DataSet
                Dad.Fill(Dst3)
                Con.Close()

workdate is every date in the month of Feb.
dateString = 1/31/2014 and datestring2 = 2/7/2014  These are strings in table and code
when I run the query Dst3 has every date in the table.
How can I get a date > than 2/7/2014????????  it is totally illogical to return every date.

thanks

gary
0
Comment
Question by:javagair
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:ktaczala
ID: 39840964
Try This:
sqlstring2 = "Select * from EmployeeAccumInfo where (WORKDATE > "'" & dateString & "'" and WORKDATE < "'" & datestring2 & "'") ORDER BY ID ASC"

sqlstring2 should look like this"
"Select * from EmployeeAccumInfo where (WORKDATE > '1/31/2014' and WORKDATE < '2/7/2014') ORDER BY ID ASC"
0
 
LVL 12

Expert Comment

by:ktaczala
ID: 39840965
You know that you are excluding the 2 dates your using, right?
0
 
LVL 12

Accepted Solution

by:
ktaczala earned 500 total points
ID: 39840971
Or try this

sqlstring2 = "Select * from EmployeeAccumInfo where (WORKDATE > "'" & dateString & "'") and (WORKDATE < "'" & datestring2 & "'") ORDER BY ID ASC"

sqlstring2 should look like this"
"Select * from EmployeeAccumInfo where (WORKDATE > '1/31/2014') and (WORKDATE < '2/7/2014') ORDER BY ID ASC"
0
 

Author Comment

by:javagair
ID: 39842666
yes I know that I was excluding those two dates.
The problem turned out to be because they are strings and one is created as a short by the vb.net code it is actually  01/01/2014
and the other is a date conversation to  string which turned out as 1/1/2014
So the query just goes down the columns looking for something that isn't there

I changed the tostring code to use:  dateString = DTPbegin.Value.ToString("MM/dd/yyyy") everywhere
and got rid of the code:    dateString = dt.ToShortDateString()

now everything works wonderful.  Sometimes we look at things as people do and not as computers do.

gary
0
 

Author Closing Comment

by:javagair
ID: 39842671
awarding points because the question is answered by myself, but kataczala gave an answer that could have been right if I knew what I was asking.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question