Click here to Skip to main content
15,915,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I Have an application that when i want to run a report to print on crystal report, i have two DayTimePicker to choose from one date to another to filter the data from the database but i only have a one single colunm for date in my database.

How can i display the selected date range from both the DayTimePicker on my crystal report generated.

eg.

From: DateTimePicker1 To: DateTimePicker2

What I have tried:

all i did is to pick the date column and place on my report template Section 1 header but it shows only the DayTimePicker1 selected date on the template but in my Section 3 which is the details in crystal report it filtered the selected dates as queried.
Posted
Updated 12-Jun-16 11:55am

1 solution

I don't know how you retrieve your data from the database and which database are you using, but if you using SQL for your database use a stored procedure where the parameters include from date and to date, you can filter this by using between on the date column in the db.

eg.

create procedure spWhatever
@startDate date,
@endDate date
as
begin
--do your select statement here
select * from tlbName where date_column between @startDate and @endDate
end


on the report set your datetimepickers to pass the values to the @startDate and @endDate parameters and on the report template pass the parameters

From: [@startDate] To: [@endDate]
 
Share this answer
 
Comments
Member 12414126 12-Jun-16 18:39pm    
Below is my code to fetch out the data from the database and paste to crystal report
private void button10_Click(object sender, EventArgs e)
{
Commstore com = new Commstore();
DataSet ds = new DataSet();
rptSalesFromDates rptsales = new rptSalesFromDates();
string from1, from2;
from1 = Datefromsales.Text;
from2 = Datetosales.Text;
ds = com.Getsalesdate(from1, from2);
if (ds.Tables[0].Rows.Count > 0)
{
rptsales.SetDataSource(ds.Tables[0].DefaultView);
crvsalesbydate.ReportSource = rptsales;
}
else
{
MessageBox.Show("No Sales Made");
}
}
while this is the sql statement
public DataSet Getsalesdate(string date1, string date2)
{
DataSet ds = new DataSet();
//string sql = "select * from POS where Date between '" + Convert.ToDateTime(date1) + "' and '" + Convert.ToDateTime(date2) + "'";
string sql = "select itemname, SUM (QntSold) AS QntSold, SUM (TotalAmnt) AS TotalAmnt from POS where Date between'" + Convert.ToDateTime(date1) + "' and '" + Convert.ToDateTime(date2) + "'GROUP BY Itemname";
SqlDataAdapter dadbt = new SqlDataAdapter(sql, mycon.Opencon());
dadbt.Fill(ds);
dadbt.Dispose();
return ds;
}
How do i go about the suggested solution you gave me cos am new to programming. any help plz

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