Click here to Skip to main content
13,738,406 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I had a table jobmaster table with a field shipment date(date/time type in shorttime format) and in a windows form I want to call all data from the table where shipment date = value from a data picker.

I tried a lot with it.
(in access database )
shipmentdate =Date/Time; format=Short Date
///////////////////////
in c# coding
<pre>class jobcodedatabean{
dateTime shipmentdate;
//also have property
}

///////////////////////////
datetime picker
dtpshipmentdate;
format=short;
assigning
jobcodedatabean.shipmentdate=dtpshipmentdate.value;
insert into jobmastertable (shipment date)values('"jobcodedatabean.shipmentdate"')

Now in my function i want to select all data from table
i used

DateTime time = dtpfromDate.Value;
 String query = "Select jobcode,companyName,vehicleno,shipmentdate,totalamount,advance,drivername,fromPlace,destination from jobmastertable  where (shipmentdate=" + @shipmentdate + ")"; 
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
dAdapter.SelectCommand.Parameters.AddWithValue("@shipmentdate", time);
DataSet ds = new DataSet();
 dAdapter.Fill(ds, "tbljobmastertable");
tblpaymentview.DataSource = ds.Tables["tblpaymentview"].DefaultView;


Help me. This returns nothing .
Posted 2-Feb-11 20:23pm
Updated 19-Feb-13 22:59pm
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

DateTime includes hours, minutes, seconds and even milliseconds so it is unlikely that the records you are looking for will match to the millisecond. So you need to find records that match anytime during the selected day. Assuming the datepicker is returning a value which represents midnight on a given day. You will want to find all records greater than the date but less than the date plus one day.

String query = "Select... where (shipmentdate => @startdate AND shipmentdate =< @endDate)";
dAdapter.SelectCommand.Parameters.AddWithValue("@startdate", time);
dAdapter.SelectCommand.Parameters.AddWithValue("@endDate", time.AddDays(1));
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

CHANGED THE PARAMETER VALUE TIME FROM

DateTime time = dtpfromDate.Value;



TO

DateTime time = dtpfromDate.Value.DATE;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100