how to fetch data from database using begin and end date and show into datagridview in c# windows forms

  • Thread starter Thread starter John6272
  • Start date Start date
J

John6272

Guest
hi, i'm facing problem to fetch data from database. I'm trying to get data from database based on begin date and end date.

here is my database query:

public static DataTable FillDataGridView(clsEntity se)
{
using (SQLiteConnection conn = new SQLiteConnection(clsDBConnection.Connection()))
{
string commandstring = "SELECT * FROM User WHERE [Date] BETWEEN @fromdate AND @todate";
using (SQLiteCommand cmd = new SQLiteCommand(commandstring, conn))
{
conn.Open();
cmd.Parameters.AddWithValue("@fromdate", se.BeginDate);
cmd.Parameters.AddWithValue("@todate", se.EndDate);
DataTable dt = new DataTable();
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
sda.Fill(dt);
return dt;
}
}
}

and here is main form code:

clsEntity se = new clsEntity();
DataTable dt = new DataTable();

se.BeginDate = dtpBeginDate.Value.ToString("dd/MM/yyyy"); //datetimepicker
se.EndDate = dtpEndDate.Value.ToString("dd/MM/yyyy");

dt = clsSalesLogic.FillInvoicesReportGridWithDates(se);
this.datagridview.DataSource = dt;


this code working and show the data based on date BUT its show only current month data, i want to show more then one month data. Code only show me current month data it did not showing the previous month data.

Also if i have no data in current month then it show blank grid, no data show.

I just want to show the whole data based on begin date and end date e.g: begin date = 15/03/2020 and end date = 02/11/2020 then show all data from 15 march to current date

But my code show only current month data it did not show the previous month data


Please help me to solve my issue.

any suggestion will help full

Continue reading...
 
Back
Top