Click here to Skip to main content
Sign Up to vote bad
good
See more: WCFLINQ
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 21 May '12 - 20:46


1 solution

you can make this:
 
[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:
// 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();
  Permalink  
Comments
Unareshraju - 22 May '12 - 3:15
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 216
1 Sergey Alexandrovich Kryukov 175
2 Tadit Dash 154
3 Richard MacCutchan 145
4 Santhosh G_ 125
0 Sergey Alexandrovich Kryukov 10,294
1 OriginalGriff 7,955
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid