我一直在尝试使用此 Web 服务返回列的总和,但它不起作用。请帮助。谢谢。我正在使用 Visual Studio 2010。它只是不断返回错误。System.InvalidOperationException:生成 XML 文档时出错。---> System.InvalidOperationException:无法序列化 DataTable。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using MySql.Data.MySqlClient;
namespace Transcript_System
{
/// <summary>
/// Summary description for check
/// </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 check : System.Web.Services.WebService
{
[WebMethod]
public DataTable connectoToMySql()
{
string connString = "SERVER=localhost" + ";" +
"DATABASE=transcriptdb;" +
"UID=root;" +
"PASSWORD=;";
MySqlConnection cnMySQL = new MySqlConnection(connString);
MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
MySqlDataReader reader;
cmdMySQL.CommandText = "SELECT SUM( Score ) FROM faculty_table WHERE Mat_No='PSC0908888'";
cnMySQL.Open();
reader = cmdMySQL.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
cnMySQL.Close();
return dt;
}
}
}