Last post Sep 21, 2012 09:15 AM by kushalrdalal
Sep 21, 2012 01:54 AM|Hajira|LINK
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...?
[WebInvoke(UriTemplate = "Appntmnts", Method = "POST")]
void Insert(Appntmnt appointment);
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);
And while testing I am passing values from REST client like this:
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
How can I get it resolved?
Any help would be appreciable...
Sep 21, 2012 09:15 AM|kushalrdalal|LINK
Just to make sure that you are getting the values from client before inserting the value try to write the values to a text file or in logs so you can make sure that the values are coming correctly from client to service and then there is a problem inserting
It could be possible that values are not coming properly from client.
If it is coming correctly then while inserting into db there cud be some issue.
For that part you can have all those values and try to run the same sql query directly to sql server and check that while inserting there are no issues like truncate or anything else.