İ want pass some values also include datetime's. I am trying this way but i am getting this error "Error converting data type nvarchar to datetime2."
This is my function;
public string InsertRezervation(int GarageId, int MemberId, string StartDate, string EndDate, bool isFinish)
{
SqlConnection connection = null;
SqlCommand command = null;
int rowsAffected = 0;
string format = "yyyyMMdd";
DateTime startDate = new DateTime(2014, 12, 18);
DateTime endDate = new DateTime(2014, 12, 25);
if (StartDate != null && EndDate != null)
{
startDate = DateTime.ParseExact(StartDate, format, CultureInfo.InvariantCulture);
endDate = DateTime.ParseExact(EndDate, format, CultureInfo.InvariantCulture);
}
connection = new SqlConnection(conn);
connection.Open();
command = new SqlCommand("Parking.Rezervation", connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add("@PGarageId", System.Data.SqlDbType.NVarChar).Value = GarageId;
command.Parameters.Add("@PMemberId", System.Data.SqlDbType.NVarChar).Value = MemberId;
command.Parameters.Add("@PStartDate", System.Data.SqlDbType.NVarChar).Value = startDate;
command.Parameters.Add("@PEndDate", System.Data.SqlDbType.NVarChar).Value = endDate;
command.Parameters.Add("@PIsFinish", System.Data.SqlDbType.NVarChar).Value = isFinish;
command.CommandText = "Parking.Rezervation";
rowsAffected = command.ExecuteNonQuery();
connection.Close();
return string.Format("You entered: {0}", rowsAffected.ToString());
}
And this is interface;
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/InsertRezervation?GarageId={GarageId}&MemberId={MemberId}&StartDate={StartDate}&EndDate={EndDate}&isFinish={isFinish}")]
string InsertRezervation(int GarageId, int MemberId, string StartDate, string EndDate, bool isFinish);
How can i fix this problem.