Click here to Skip to main content
12,951,548 members (48,421 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 ...
Posted 20-Sep-12 19:44pm
cutie1297
Updated 20-Sep-12 19:46pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,084
CHill60 3,480
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,830


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100