I have an Database Table containing columns, 2 columns of my problem concern are:
- column Date
- column Time
I'm using that Table to show data by DateTime
On my form I have:
- 4 dateTimePickers (2 of them for Date, 2 of them for Time)
- dataGridView
- button
On button click I would like to populate dataGridView with data that's between 2 DateTimes:
I don't know why but it seems it's ignoring WHERE part cause dataGridView is populated with all Data from Table
OR
It's treating Vrijeme as string
But when my SQL Query looks like this:
dataGridView is populated only with Data which has DateTime equal to Od;
EDIT: After some more combinations I've come to conclusion it's ignoring Date part in Od (So if I change Time part it'll show me all Data in that TimeSpan but as much I change Date I allways get all Data)
- column Date
- column Time
I'm using that Table to show data by DateTime
On my form I have:
- 4 dateTimePickers (2 of them for Date, 2 of them for Time)
- dataGridView
- button
On button click I would like to populate dataGridView with data that's between 2 DateTimes:
Code:
private void button1_Click(object sender, EventArgs e) { string Od, Do; Od = dateTimePicker1.Value.ToString("yyyy-MM-dd") + " " + dateTimePicker2.Value.ToString("HH:mm:ss"); Do = dateTimePicker3.Value.ToString("yyyy-MM-dd") + " " + dateTimePicker4.Value.ToString("HH:mm:ss"); dsu = new DataSet(); string sqlu = "SELECT CAST(Racun.datum AS DATETIME) + CAST(Racun.vrijeme AS DATETIME) AS Vrijeme From Racun WHERE Vrijeme >='" + Od + "' AND Vrijeme <='" + Do + "'"; dau = new SqlDataAdapter(sqlu, con); dau.Fill(dsu, "Hotel"); dataGridView1.DataSource = dsu.Tables[0]; foreach (DataGridViewColumn column in dataGridView1.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } }
OR
It's treating Vrijeme as string
But when my SQL Query looks like this:
Code:
string sqlu = "SELECT CAST(Racun.datum AS DATETIME) + CAST(Racun.vrijeme AS DATETIME) AS Vrijeme From Racun WHERE Vrijeme ='" + Od + "'";
EDIT: After some more combinations I've come to conclusion it's ignoring Date part in Od (So if I change Time part it'll show me all Data in that TimeSpan but as much I change Date I allways get all Data)
Comment