0
我試圖從數據庫數據綁定到一個DataTable對象,但我不斷收到此錯誤:從數據庫向表中分配數據時出錯?
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)
我相信這意味着有來自地方,併發送一個文本\ HTML未來的錯誤。 但是,如果我使用我的aspx文件中的sqldatasource標記將數據綁定到我的grif,它就會很好地綁定。
下面是我的web服務文件中的函數:
[WebMethod]
public DataTable getTable()
{
DataTable myTable = new DataTable("AMR_COUNTY");
ConnectionStringSettingsCollection s = ConfigurationManager.ConnectionStrings;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["wmoddevsql02.ePCR310_Server.dbo"].ToString()))
using (SqlCommand cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = string.Format("SELECT * FROM AMR_COUNTY");
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd))
dataAdapter.Fill(myTable);
}
return myTable;
}
}
,這裏是在叫我的代碼隱藏:
DataTable dataTable = new DataTable();
using (MCMwebservice.Service1SoapClient myWebService = new MCMwebservice.Service1SoapClient())
{//use the session set userID to query Database for all incidents for the logged in user
dataTable = myWebService.getTable();
WebDataGrid1.DataSource = dataTable;
WebDataGrid1.DataBind();
}
謝謝,想通了我沒有連接字符串列在Web服務的congif文件 –