You must Sign In to post a response.
  • Category: WCF

    Insert the data to db using Wcf

    I am creating a wcf application and to consume in ASP.NET.

    IN ISERVICE .CS File i have wrote a below code

    [OperationContract]
    string insertuser(Employeedetails employee);

    }
    [DataContract]
    public class insertuser
    {
    [DataMember]
    public string name { get; set; }
    [DataMember]
    public string sex { get; set; }
    [DataMember]
    public string Department { get; set; }
    [DataMember]
    public int Salary { get; set; }

    }

    In SVC.cs file

    public string insertuser(Employeedetails employee)
    {

    SqlConnection Sqlcon = new SqlConnection("Connectionstring");
    //Employeedetails EM = new WcfService.Employeedetails();
    string name=string.Empty;
    string sex=string.Empty;
    string Department = string.Empty;
    int salary=0;
    string message = string.Empty;
    insertuser isu = new WcfService.insertuser();
    name = isu.name.ToString();
    sex = isu.sex.ToString();
    Department = isu.Department.ToString();
    salary = isu.Salary;

    SqlCommand cmd = new SqlCommand("insert into employee(name,sex,department,salary)values('" + name.ToString() + "','" + sex.ToString() + "', '" + salary + "')", Sqlcon);
    Sqlcon.Open();
    int result= cmd.ExecuteNonQuery();
    if (result == 1)
    {
    message = "Details are isnerted Sucessfully";

    }
    else
    {
    message = "Details are not inserted Sucessfully";

    }
    Sqlcon.Close();
    return message;



    throw new NotImplementedException();
    }
    }


    }

    Then i have created a asp.net application for consuming using Addreference method
    in the new file i created four textbox and button.

    in the button event

    i wrote the below code
    ServiceReference1.Service1Client objService = new ServiceReference1.Service1Client();
    objService.insertuser(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)

    im facing the below Error: Method are not implemented
  • #769359
    Hi,

    Check below given link:
    http://www.aspmantra.com/2015/08/how-to-insert-record-into-sql-server-database-wcf-service-c-charp.html">http://www.aspmantra.com/2015/08/how-to-insert-record-into-sql-server-database-wcf-service-c-charp.html
    http://www.aspmantra.com/search/label/WCF

  • #769360
    Hi

    Why you have written the line throw new NotImplementedException(); remove it.
    Add try catch blocks in insertuser implementation so that you can know the exception if any.

    Sridhar Thota.
    Editor: DNS Forum.


  • Sign In to post your comments