⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeeservice.cs

📁 《ASP.NET 2.0 XML 高级编程(第3版)》 《ASP.NET 2.0 XML 高级编程(第3版)》
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Configuration;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class EmployeeService : System.Web.Services.WebService
{
    public EmployeeService () 
	{
    }

    [WebMethod]
    public XmlDocument GetEmpDetailsByEmpID(int employeeID)
    {
        try
        {
            string connString = WebConfigurationManager.ConnectionStrings
              ["adventureWorks"].ConnectionString;
            using (SqlConnection sqlConnection = new SqlConnection(connString))
            {
                DataSet employeeDataset = new DataSet("EmployeesRoot");
                SqlDataAdapter adapter = new SqlDataAdapter();
                SqlCommand command = new SqlCommand
                  ("Select EmployeeID, Title, CAST(BirthDate AS char(12)) " +
                  "AS BirthDate, MaritalStatus from HumanResources.Employee " +
                  "as Employees Where EmployeeID =" + employeeID.ToString(),
                  sqlConnection);
                command.CommandType = CommandType.Text;
                adapter.SelectCommand = command;
                //Fill the Dataset with the return value from the stored procedure
                adapter.Fill(employeeDataset, "Employees");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(employeeDataset.GetXml());
                return xmlDoc;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -