Solved

why am I getting too many items in dataset

Posted on 2014-02-06
5
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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