我一直在使用此Web服務返回列的總和,但它不起作用。請幫助。謝謝。 我正在使用Visual Studio 2010.It只是在返回一個error.System.InvalidOperationException:生成XML文檔時發生錯誤。 ---> System.InvalidOperationException:無法序列化DataTable。使用ASP.NET WEB服務返回列的總和
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;
}
}
}
+1最佳的解決方案! – gleng
感謝您的幫助,但它返回此錯誤。 錯誤不能將類型'object'隱式轉換爲'string'。存在明確的轉換(您是否缺少演員?)。請給我更多的幫助。上帝祝福你。它的我的學校項目 –
做'mySqlcommand.ExecuteScalar()。ToString();' – Jonesopolis