Hi,
I created a WCF REST service in which I m trying to insert records in SQL.I m testing it with REST client.When Im inserting values some values are getting inserted and some values are inserted as NULL eventhough I pass values from frontend.I couldn't understand what might be the reason for this...?
My code for insertion goes like this:
IService.cs:
[OperationContract]
[WebInvoke(UriTemplate = "Appntmnts", Method = "POST")]
void Insert(Appntmnt appointment);
Service1.cs:
public void Insert(Appntmnt appointment)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = (ConfigurationManager.ConnectionStrings["c"].ConnectionString);
string b = "";
DateTime a = default(DateTime);
DateTime c = default(DateTime);
appointment.AppointmentId = Guid.NewGuid();
a = Convert.ToDateTime(appointment.Date);
appointment.Status = "Checkout";
if ((appointment.DOB) != "" && appointment.DOB != null)
{
c = Convert.ToDateTime(appointment.DOB);
}
if (appointment.Gender != null)
{
b = Convert.ToString(appointment.Gender);
}
appointment.CreatedDateTime = DateTime.Now;
string s1 = "Insert into Appointment(AId,CId,PId,Date,TimeStart,TimeEnd,UserId,Reason,PatientFirstName,PatientLastName,PatientDOB,PatientGender,Status,ServiceId,ReferedBy,CreatedUserId,CreatedDateTime)values('" + appointment.AppointmentId + "', '" + appointment.CompanyId + "','" + appointment.ProviderId + "', '" + appointment.Date + "', '" + appointment.TimeStart + "', '" + appointment.TimeEnd + "','" + appointment.UserId + "','" + appointment.Reason + "','" + appointment.FirstName + "','" + appointment.LastName + "','" + appointment.DOB + "','" + appointment.Gender + "','" + appointment.Status + "','"+appointment.ServiceId+"','"+appointment.ReferedBy+"','" + appointment.CreatedUserId + "','" + appointment.CreatedDateTime + "')";
SqlCommand cm = new SqlCommand(s1, cn);
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
}
And while testing I am passing values from REST client like this:
<Appntmnt>
<CId>b9ca2e32-ce88-4d72-99ce-9bc592511e85</CId>
<PId>ec245cf7-b8a2-4142-8f90-8ecd2f6bb037</PId>
<Date>9/23/2012</Date>
<TimeStart>11:15</TimeStart>
<TimeEnd>11:30</TimeEnd>
<UserId>ec245cf7-b8a2-4142-8f90-8ecd2f6bb037</UserId>
<Reason>general Consulation</Reason>
<FirstName>John</FirstName>
<LastName>Williams</LastName>
<DOB>1985/7/5</DOB>
<Gender>M</Gender>
<CreatedUserId>ec245cf7-b8a2-4142-8f90-8ecd2f6bb037</CreatedUserId>
</Appntmnt>
When I test are values are getting inserted in SQL but not all the values are inserted.Eventhough I pass FirstName,LastName,Gender,Date here they are not inserted remaining all value are inserted.I want all the values which I pass to be inserted in SQL.
How can I get it resolved?
Any help would be appreciable...
Thanks ...