Let me ask again. I am a PHP developer for two years. First, with Java I got my hands for a year and C # for at least a few months before Java. I am in the process of releasing C # The following C # SQL
, which determines if the reservation entry ( [RESERVATION]
from the table) overlaps with existing pending
reservation ( as the [status] [r]
where the filter is filtered by)
string query = "select [r]. [[RD], [first_name], [middle-name], [nickname], [ex [Reservation_time] and [reservation_time] between [reservation_time] and [reservation_time], [RSS + R]. [[Customer_id] = [c] [id] "[" reservation_data] = @ reservation_date and "+" [reservation_time] [Reservation_time "+") or "+" reserved for "[R"] between "reservation" time between [reservation_time_from] and "+" @reservation_time_from and @reservation_ between "reservation_time_from and @reservation_time_to" or [reservation_time_to] or " ([Reservation_time_from] Time_to "+") and "+" [status] = 'Pending' "" sequence by [transaction_date] asc ";
I've attached parameters using this method:
command. Parameter. AddWithValue ();
Now when I execute a query using command.ExecuteReader ()
, then it looks like the query [reservation] > Does not overlap schedule
. I've got a hump that has something to do with the source of the data: this is a DateTimePicker
object; Because the column types of columns are only date
, but I'm not completely sure. I have attached the value of the picker at that time using this code (which is a parameter for the time
column):
command.Pameters.Advith Value ("@ Reservation_time", "SqlDbType.Date) .value = ((datetime) absolute [value]). Timeoffaid;
Can anyone help me? However, although some parameters (E.g. @reservation_time_from
) has the string
on at least twice the query. Thanks for support.
edit Do:
This is how I add the parameter (sorry that the previous example is pasted incorrectly, it is):
command parameter.advat value (" @RGI_Nime "," SqlDbType.Time ") value = ((DateTime) Ultimate ['Reservation_time' ']) Timeoffaid; Order parameter.Advate Value (" @ reservation_time "," SqlDbType.Time ") value = ( (DateTime) Ultimate ['Reservation_time'] ']]. Timeoffaid; Order parameter.advat value ("@ reservation_data from", SqlDbType.Date). Value = (( Dated time) Ultimate [ 'reservation_date_from']) date; order. Parameter. Advant Value ("@ reservation_data,", SqlDbType.Date). Value = ((Date time) Highest ['Reservations / Data']] ') date;
takes value as the second parameter, and SqlDbType as the parameter value is interpreting. You need to use AddWithValue
:
Command.Pameters.ed ("@ reservation_time_from", SqlDbType.Time) instead of Add
Will be. Value = ((Date time) Ultimate [Value]). Timing;
From the document:
AddWithValue changes the SqlParameterCollection.Add method that takes a string and an object. Which takes a string and an object was deprecated due to possible ambiguity with the SqlParameterCollection.Add surcharge, which takes the string and a SqlDbType calculation value where an integer with the string can be passed either Parameter value or related SqlDbType value.
Edit: You are only doing the same thing because SqlCommand is correctly assigning SqlDbType based on the value given in the value
Set and SqlDbType is irrelevant: Run this code to see:
var cmd = new SqlCommand (); Var param = cmd.Parameters.AddWithValue ("@ date_from", SqlDbType.Date); Console.WriteLine (param.ParameterName); Console.WriteLine (param.SqlDbType); Console.WriteLine (param.Value.GetType ()); Console.WriteLine (); Param.Value = DateTime.Today; Console.WriteLine (param.ParameterName); Console.WriteLine (param.SqlDbType); Console.WriteLine (param.Value.GetType ());
This output:
@date_from int system.Data. SQLDB type @ date-from datetime system. DateTime
No comments:
Post a Comment