I need to ask something again. I'm a PHP developer for two years. Previously, I got my hands with Java for a year and C# for at least some couple of months before Java. I'm in the process of relearning C#. The following C# string declaration is from a tested SQL script that determines if a reservation entry (from the [RESERVATION] table) overlaps with an existing Pending reservation (filtered by the [status] as [r] where clause)
string query = "select [r].[id], [first_name], [middle_name], [surname], [extension], [reservation_time_from], [reservation_time_to] " +
"from [RESERVATION] as [r] " +
"join [CUSTOMER] as [c] on [r].[customer_id] = [c].[id] " +
"where [reservation_date] = @reservation_date and " +
"( @reservation_time_from between [reservation_time_from] and [reservation_time_to] or " +
"@reservation_time_to between [reservation_time_from] and [reservation_time_to] " +
") or " +
"( [reservation_time_from] between @reservation_time_from and @reservation_time_to " +
"or [reservation_time_to] between @reservation_time_from and @reservation_time_to " +
") and " +
"[status] = 'Pending' " +
"order by [transaction_date] asc";
I attached the parameters using this method:
command.Parameters.AddWithValue();
Now when I perform the query using the command.ExecuteReader(), it seems that the query does not fetch overlap schedules of [RESERVATION]. I got a hunch that it has something to do with the source of the data: that is a DateTimePicker object; since the column type of the columns are date only, but I'm not quite sure. I attached the values of those time picker using this code (that is a parameter for a time column):
command.Parameters.AddWithValue("@reservation_time_from", SqlDbType.Date).Value = ((DateTime)param[value]).TimeOfDay;
Can someone assist me? Note though that some parameters (such as @reservation_time_from) occurred at least twice on the query string. Thanks for the support.
EDIT:
These is how I attached parameters (sorry the previous example is wrongly pasted, Tee hee):
command.Parameters.AddWithValue("@reservation_time_from", SqlDbType.Time).Value = ((DateTime)param['reservation_time_from']).TimeOfDay;
command.Parameters.AddWithValue("@reservation_time_to", SqlDbType.Time).Value = ((DateTime)param['reservation_time_to']).TimeOfDay;
command.Parameters.AddWithValue("@reservation_date_from", SqlDbType.Date).Value = ((DateTime)param['reservation_date_from']).Date;
command.Parameters.AddWithValue("@reservation_date_to", SqlDbType.Date).Value = ((DateTime)param['reservation_date_to']).Date;