使用Web服务执行SQL脚本c#

时间:2016-06-15 14:32:07

标签: c# .net

我是C#编程新手,日复一日还在学习。如何创建executionql Web服务来检索数据?

SELECT ID,Function,Level,Type FROM Machines WHERE Type IN(2,10)AND Level> 1

webconfig:

 <connectionStrings>
    <add name="TConnectionString" connectionString="Data Source=      
     ExternalDataSource;Initial Catalog=DB;Integrated Security=True"    
     providerName="System.Data.SqlClient"/>
 </connectionStrings>

在WebMethod下我是否需要检索SQL查询中的所有字段?

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.Services;

namespace EmployeeRecs
 {
  /// <summary>
  /// Summary description for Service1
  /// </summary>
 [WebService(Namespace = "http://tempuri.org/")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 [System.ComponentModel.ToolboxItem(false)]
 // To allow this Web Service to be called from script, using ASP.NET AJAX,   
  uncomment the following line. 
 // [System.Web.Script.Services.ScriptService]
 public class Service1 : System.Web.Services.WebService
 {

           //Create new web method to get details
    [WebMethod]
    public string GetDetails(int ID, string Function,int Level,string Type)
    {
        return Details(firstName);

     }
 }
 } 

任何帮助将不胜感激!

0 个答案:

没有答案