Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a sql table(emp_id,ename,e_sal).now i want to inserting some rows through the client application.
here i need to create a wcf service to inserting the data into sqldatabase through the LINQ for that how can create a wcf service to inserting the data into sqlDB.

note: this service has three inserting parameters are(emp_id,ename,e_sal).

please any body help to me.
thanks in advance.......

thanks and regards,
naresh
Posted

1 solution

you can make this:

C#
[DataContract]
public class Employee
{
  [DataMember]
  public int Id;

  [DataMember]
  public string Name;

  [DataMember]
  public decimal Salary;
}

[ServiceContract]
public interface IService
{
  [OperationContract]
  void AddEmployee(Employee employee);
}


Implement method AddEmployee in server and just call it from client. Client should now nothing about SQL, otherwise its no point to make WCF.

As for insert phase implementation it has nothing to do with WCF. Refer to LinqToSQL using-linq-to-sql-part-1 or Simple-LINQ-to-SQL-in-C

If you have DataContext then you can do following:
C#
// connect
MyDataCotext db = new MyDataCotext();

// generate new record
EmployeeRecord/*(this is what comes from DBContext)  */ emp = new EmployeeRecord();

// assign values
emp.Id = Employee.Id
emp.Name = Employee.Name
emp.Salary = Employee.Salary

// add to database
db.EmployeeRecords.Add(emp);
db.SubmitChanges();
 
Share this answer
 
v3
Comments
Unareshraju 22-May-12 3:15am    
hi shawnas thanks to u r reply,
i was connected to database through the LINQ for that no need to declare data contract,
i am inserting the values through the my application(wpf in that text boxes) .please any help how write insert command when i am inserting values through the my application

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900