473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

retrieve records between dates selected from datetimepicker and of selected date

i want to retrieve the records selected between from_dt and to_dt and also the records of the selected date should be retrieved...

Expand|Select|Wrap|Line Numbers
  1. SELECT ChallanDtl.chalID, ChallanDtl.chalTo, 
  2. ChallanDtl.chalNo, ChallanDtl.chalDDate,
  3. ChallanDtl.chalYourNo, ChallanDtl.chalPO_NO, 
  4. ChallanDtl.chalPO_Date, 
  5. ChallanSubDtl.chalsubdescription, 
  6. ChallanSubDtl.chalsubQty  FROM ChallanDtl INNER JOIN 
  7. ChallanSubDtl ON ChallanDtl.chalID = 
  8. ChallanSubDtl.ChalID where ChallanDtl.chalPO_Date >= '" 
  9. + frm_dtpicker.value + "' and ChallanDtl.chalPO_Date 
  10. <='" + to_dtpicker.value + "'", cn);
this is my query please reply.. me with the query as soon as possible with the above query i m not getting all the records.... when i select the same date in both datetimepicker no record is displayed... i also want the record of the selected dates from both datetime picker..
Mar 4 '13 #1
2 8191
Rabbit
12,516 Expert Mod 8TB
We need additional information.

1) Output of the SQL string that it's trying to execute
2) The metadata of the table
3) The name of the database engine you're using
Mar 4 '13 #2
arie
64
When user picks date in DateTimePicker, it's Value property is set to DateTime.Now. This means that, aside from 'date' value, you have also picked 'time' value. Also, when you're using DateTimePicker.Value to construct sql query in a way shown in your code, what you really get is DateTimePicker.Value.ToString(), which depends on property Format of DateTimePicker and CultureInfo set for your system/thread/application. Since date and time are displayed differently in different countries (e.g. sometime monts and days switch places), using value of DateTime without first formatting it (so your database engine understands) isn't very safe.

I don't know what database you're using, but most databases will understand querries correctly if you use this to format datetime:

Expand|Select|Wrap|Line Numbers
  1. DateTime fromDate = frm_dtpicker.Value;
  2. string formatedDateTimeString = String.Format("{0:yyyy-MM-dd HH:mm:ss}", fromDate);
Regarding your other problem (query is not getting all the records): to choose a period of time properly, you simply need to choose (midnight of fromDate, midnight of toDate + 1 day), so:

Expand|Select|Wrap|Line Numbers
  1. DateTime fromDate = frm_dtpicker.Value.Date;
  2. DateTime toDate = to_dtpicker.Value.Date.AddDays(1);
Then, if the date chosen in frm_dtpicker is the same as the is the date chosen in to_dtpicker, e.g "2012-03-31", you should get 24 hours:

fromDate: 2012-03-31 00:00
toDate: 2012-04-01 00:00
Mar 5 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Brian Henry | last post by:
is there anyway to get a bolded date on aq date time picker dropdown like you can in the calendar control? i need to mark "active" dates in bold but dont want a huge calendar control taking up the...
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
0
by: padhuwork | last post by:
Hi, I want to create a Windows DLL using VC++ 6.0 which connects to SQL Server. After establishing the connection, I want to retrieve records from table (query) and out put the recordset to a...
14
by: David | last post by:
Hi, I have a form on which a user can select a checkbox against a record. Each checkbox carries the RecordID of a product. ---------------------------------------------------------------- I...
1
by: Jesse | last post by:
Hi, I am working on datetimepicker and want make the dates out of my range disabled. There are APIs that I have used: minDate, maxDate. It works fine. However, users can not tell which date can't...
2
by: Patrick Pirtle | last post by:
Having programmed for a number of years with VB6 (but very little database stuff), I'm trying to learn Visual Studio, but am just about at the end of my rope as far as wrapping my mind around...
4
by: Evanescent | last post by:
Hi Guys, I am trying to create a form which allows the users to retrieve records based on the values entered or chosen in the various combo boxes and textboxes, such as the customer's name, invoice...
2
by: JohanKotze | last post by:
I design a report that will show all the records for a particular client and all the records do show in the report BUT when I try to search between dates than only half of the records are showing...
2
by: bytes access nubie | last post by:
When a query is run, i want a prompt displayed allowing the user to enter < DATE to find all records less than the specific date. e.g. < 1/1/2011. I know how to do that with a start date AND...
4
by: Emmanuel Ayivi | last post by:
I created a table called "tblfeesdetails" with fields; "groupid", "Academic_year", "Term", "Insect_date and time" and these fields are updated base on a command button click and the update date and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.