如何编写插入查询 [英] how to write insert query

查看:111
本文介绍了如何编写插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个sql table(emp_id,ename,e_sal).现在我想通过客户端应用程序插入一些行.
在这里,我需要创建一个wcf服务以通过LINQ将数据插入sqldatabase中,以便如何创建wcf服务以将数据插入sqlDB中.

注意:此服务具有三个插入参数,分别是(emp_id,ename,e_sal).

请任何人帮助我.
在此先感谢.......

感谢和问候,
naresh

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

推荐答案

您可以这样做:

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);
}



在服务器中实现方法AddEmployee,然后从客户端调用它.客户端现在应该对SQL一无所知,否则就没有必要进行WCF了.

至于插入阶段的实现,它与WCF无关.请参阅LinqToSQL using-linq-to-sql -part-1 Simple-LINQ-to-SQL-in -C

如果您具有DataContext,则可以执行以下操作:



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();


这篇关于如何编写插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆