Hiii
There is a Windows Form with a DataGridView, two TextBoxes and a Button.
date range is given in the TextBoxes as from and to dates.
my problem is when I give date range of the same month, e.g. 05/08/2018 to 20/08/2018, it gives correct records within the date range but, when I give date range within two or more months, e.g. 15/08/2018 to 11/09/2018, it gives all the records regardless the date range given!!! I do not understand what is the problem.
Here is my query...
Select BillSrNo, BillNumber, BillCustName, BillAmtPaid From Billings Where BillDate Between'" + txtFromDt.Text + "' AND '" + txtToDt.Text + "' Order By BillSrNo
Please note that I use MS Access and the DataType is Text. Previously I have tried the same with DateTimePicker and DataType as Date/Time but it gives error. I want to use TextBox, is it possible?
Why it is not giving correct data when date range is between two or more months ?
Thanks
Mayank Jani

Amit GuptaRank #190 · 12.8K reputationPosted Sep 9, 2018, 9:25 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Sep 5, 2018, 10:09 AM EDT
Mayank JaniRank #2,449 · 575 reputationPosted Sep 6, 2018, 9:44 PM EDT
if (MyConnAcc.State == ConnectionState.Closed)
MyConnAcc.Open();
FetchBillList.Connection = MyConnAcc;
FetchBillList.CommandText=("Select BillSrNo, BillNumber, BillCustName, BillAmtPaid From Billings Where BillDate Between @Fdate AND @TDate Order By BillSrNo");
FetchBillList.Parameters.Add("@FDate", OleDbType.Date);
FetchBillList.Parameters.Add("@TDate", OleDbType.Date);
FetchBillList.Parameters["@FDate"].Value = dtpFrom.Value.ToShortDateString();
FetchBillList.Parameters["@TDate"].Value = dtpTo.Value.ToShortDateString();
FetchBillList.ExecuteNonQuery();
OleDbDataReader ReadData = FetchBillList.ExecuteReader();
if(ReadData.Read())
//Here I need to show the data into a DGV
Amit GuptaRank #190 · 12.8K reputationPosted Sep 6, 2018, 10:00 PM EDT
Mayank JaniRank #2,449 · 575 reputationPosted Sep 7, 2018, 3:31 AM EDT
dgvBillList.Columns[0].HeaderText = "Sr.";
dgvBillList.Columns[1].Width = 90;
dgvBillList.Columns[1].HeaderText = "Bill No."; //and so on...
Amit GuptaRank #190 · 12.8K reputationPosted Sep 7, 2018, 4:53 AM EDT
Mayank JaniRank #2,449 · 575 reputationPosted Sep 7, 2018, 8:20 AM EDT
OleDbDataReader ReadData = FetchBillList.ExecuteReader();
if(ReadData.Read()) //Working good till here.
{
dgvBillList.DataSource = (what should I write here to connect the data with the DGV? or is there anyother way to do so??)
dgvBillList.Columns[0].Width = 32; //Here it throws error.
dgvBillList.Columns[0].HeaderText = "Sr.";
dgvBillList.Columns[1].Width = 90;
dgvBillList.Columns[1].HeaderText = "Bill No.";
dgvBillList.Columns[2].Width = 90; ...
Mayank JaniRank #2,449 · 575 reputationPosted Sep 7, 2018, 9:13 AM EDT
{
DataTable dt = new DataTable();
dt.Load(ReadData);
dgvBillList.DataSource = dt;
dgvBillList.Columns[0].Width = 32;
dgvBillList.Columns[0].HeaderText = "Sr.";
dgvBillList.Columns[1].Width = 90;
dgvBillList.Columns[1].HeaderText = "Bill No.";
dgvBillList.Columns[2].Width = 90; ...
Amit GuptaRank #190 · 12.8K reputationPosted Sep 7, 2018, 9:28 AM EDT
Mayank JaniRank #2,449 · 575 reputationPosted Sep 8, 2018, 5:02 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Sep 8, 2018, 12:41 PM EDT
Mayank JaniRank #2,449 · 575 reputationPosted Sep 8, 2018, 9:16 PM EDT
Mayank JaniRank #2,449 · 575 reputationPosted Sep 10, 2018, 8:42 AM EDT