Answer the question
In order to leave comments, you need to log in
Passing DataTimePicker value to SQL query in C#?
Hello.
There is a Windows Forms project in C #, using an Access database. Different sorting works with standard built-in queries and output
this.hotelTableAdapter.FillByLonger(this.hoteldbDataSet.hotel);
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime result = dateTimePicker1.Value;
this.Text = result.ToString();
}
SELECT id, [ФИО проживающего], [Дата заселения], [Дата выселения], [Гостиничный номер]
FROM hotel
WHERE ([Дата выселения] LIKE '" + dateTimePicker1.Text"')
Answer the question
In order to leave comments, you need to log in
You are asking for sorting and at the same time passing the date to "WHERE" ... If I understand you correctly, then you need the following:
var sqlCmd = new SqlCommand(@"SELECT id,
[ФИО проживающего],
[Дата заселения],
[Дата выселения],
[Гостиничный номер]
FROM hotel
WHERE ([Дата выселения] LIKE '@dpDate')"");
sqlCmd.Parameters.Add("@dpDate", SqlDbType.DateTime);
sqlCmd.Parameters["@dpDate"] = dateTimePicker1.Value;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question