這似乎並沒有很好地工作的任何幫助查詢之間似乎並沒有很好地工作
this.con.Open();
string selectCommandText = "Select * from paymentrecord where Payment_date >= " + dateTimePicker2.Value.ToString("dd-MM-yyyy") + " and Payment_date <" + dateTimePicker1.Value.ToString("dd-MM-yyyy") + "";
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommandText, this.con);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
this.dataGridView1.DataSource = dataTable;
this.con.Close();
這其中也似乎並沒有很好地工作。它讓我從不同日期的記錄,有時嫌我沒有得到任何記錄,而他們與我選擇
this.con.Open();
string selectCommandText = "Select * from paymentrecord where Payment_date BETWEEN " + dateTimePicker2.Value.ToString("dd-MM-yyyy") +" and "+ dateTimePicker1.Value.ToString("dd-MM-yyyy") + "";
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommandText, this.con);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
this.dataGridView1.DataSource = dataTable;
this.con.Close();
格式化您的代碼並解釋問題。 – FCin
[SQL注入警報](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx) - 您應該**不**將您的SQL語句連接在一起 - 使用**參數化查詢**而不是爲了避免SQL注入 - 檢出[Little Bobby Tables](https://xkcd.com/327/) –
使用參數化查詢,您將獲得安全性和預期結果。兩個爲一個 –