I want to insert data into database.
iserviceemp:
[ServiceContract]
public interface IServiceAuthor
{
[OperationContract]
string InsertEmployeeDetails(EmpDetails emp);
}
public class EmpDetails
{
string name = string.Empty;
string address = string.Empty;
string dept = string.Empty;
[DataMember]
public string Name
{
get { return name; }
set { name = value; }
}
[DataMember]
public string Address
{
get { return address; }
set { address = value; }
}
[DataMember]
public string Department
{
get { return dept; }
set { dept = value; }
}
}
serviceemp:
public string InsertEmployeeDetails(EmpDetails emp)
{
string Message;
//SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Rajesh;User ID=sa;Password=wintellect");
con.Open();
SqlCommand cmd = new SqlCommand("insert into Employee(Name,Address,Department) values(@Name,@Address,@Department)", con);
cmd.Parameters.AddWithValue("@Name", emp.Name);
cmd.Parameters.AddWithValue("@Address", emp.Address);
cmd.Parameters.AddWithValue("@Department", emp.Department);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
Message = emp.Name + " Details inserted successfully";
}
else
{
Message = emp.Name + " Details not inserted successfully";
}
con.Close();
return Message;
}
i have created service i want to consume in mvc application i have created empcontroller
iam stuck here how to use service and how to insert data.