📄 employeeservice.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 + -