Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 )
C#
shipmentdate =Date/Time; format=Short Date
///////////////////////
in c# coding
<pre>class jobcodedatabean{
dateTime shipmentdate;
//also have property
}

///////////////////////////
datetime picker
dtpshipmentdate;
format=short;
assigning
C#
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

C#
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
Updated 19-Feb-13 22:59pm
v4

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));
 
Share this answer
 
CHANGED THE PARAMETER VALUE TIME FROM

DateTime time = dtpfromDate.Value;



TO

DateTime time = dtpfromDate.Value.DATE;
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900