Purpose of the application is to select data from Sql database to the windows form data grid. I implemented the custom format for the date time picker but am still receiving this error. Here's the properties and following code of the application
private void startTimePicker1_MouseDown(object sender, MouseEventArgs e)
{
startTimePicker1.CustomFormat = "yyyy-MM-dd hh:mm:ss";
startTimePicker1.Format = DateTimePickerFormat.Custom;
}
private void endTimePicker1_MouseDown(object sender, MouseEventArgs e)
{
endTimePicker1.CustomFormat = "yyyy-MM-dd hh:mm:ss";
endTimePicker1.Format = DateTimePickerFormat.Custom;
}
private void loadBtn_Click(object sender, EventArgs e)
{
startTimePicker1.CustomFormat = "yyyy-MM-dd hh:mm:ss";
startTimePicker1.Format = DateTimePickerFormat.Custom;
endTimePicker1.CustomFormat = "yyyy-MM-dd hh:mm:ss";
endTimePicker1.Format = DateTimePickerFormat.Custom;
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["DBName"].ConnectionString))
{
if(db.State==ConnectionState.Closed)
{
db.Open();
string query = "select z.ItemName, x.Quantity, x.CreateDate" +
" from Invoice_Itemized x inner join Inventory z on x.ItemNum = z.ItemNum inner join Departments d on z.Dept_ID = d.Dept_ID" +
$"where x.CreateDate BETWEEN '{ startTimePicker1 }' and '{ endTimePicker1 }' and d.SubType = 'TYPE'";
liquorBindingSource.DataSource = db.Query<Liquor>(query, commandType: CommandType.Text);
}
}
Query outputs following value at runtime
select z.ItemName, x.Quantity, x.CreateDate from Invoice_Itemized x inner join Inventory z on x.ItemNum = z.ItemNum inner join Departments d on z.Dept_ID = d.Dept_IDwhere x.CreateDate BETWEEN 'System.Windows.Forms.DateTimePicker, Value: 7/18/2018 2:44:00 AM' and 'System.Windows.Forms.DateTimePicker, Value: 7/18/2018 4:19:01 AM' and d.SubType = 'TYPE'
This query successfully executes in SSMS, I've ran into a huge wall after several hours of debugging this mess.