我有一个MS-SQL服务器,我在C#中创建了一个不能正确检索一些法语名称的Web服务。例如,我为“é”和“è”获得了奇怪的角色组合。我想知道我是否需要使用另一个库,或直接提到一个特殊的编码。谢谢!这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Collections;
using Newtonsoft.Json;
using System.IO;
using System.Threading.Tasks;
using System.Text;
using System.Security.Cryptography;
namespace WebApplication
{
[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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public void getTotalForDateIntervalEmployees(string startDate, string endDate)
{
string cs = ConfigurationManager.ConnectionStrings["vetDatabase"].ConnectionString;
List<Employee> master = new List<Employee>();
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("CountAndGroupByObservations", con);
cmd.CommandType = CommandType.StoredProcedure;
//Linking SQL parameters with webmethod parameters
SqlParameter param1 = new SqlParameter()
{
ParameterName = "@startDate",
Value = startDate
};
SqlParameter param2 = new SqlParameter()
{
ParameterName = "@endDate",
Value = endDate
};
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Employee employee = new Employee();
employee.building = rdr["Building"].ToString();
employee.name = rdr["reportedBy"].ToString();
employee.total = Convert.ToInt32(rdr["total"]);
master.Add(employee);
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(master));
}
}