我试图解决这个问题,但是当我这样做时我得到了一个疯狂的错误?
这是我的第一个方法 --> 其中包含 SQLQUERY
[WebMethod]
public ArrayList getAllaEgenskaperforenmall(string mall_id)
{
ArrayList dbFetch;
// string parameter1 = "mall_namn";
string sqlReadQuery = "SELECT DISTINCT d.egenskaper_namn FROM(SELECT egen.egenskaper_id, egen.egenskaper_namn, kopp.mall_id, kopp.egenskap_id, emall.mall_id as egenskapensmallid, emall.mall_namn FROM t_egenskaper as egen, t_kopplingmallegenskaper as kopp, t_egenskapsmall as emall WHERE kopp.mall_id = 1 AND kopp.egenskap_id = egen.egenskaper_id) as d";
dbFetch = executeReadSqlQueryArray(sqlReadQuery);
return dbFetch;
}
然后我尝试建立一个可以为我获取数据的通用网络方法。
public ArrayList executeReadSqlQueryArray(string sqlToFetchData, string parameter1 = "", string parameter2 = "", string parameter3 = "")
{
SqlConnection conn = new SqlConnection(mConnectionstring);
SqlCommand command = new SqlCommand();
SqlDataReader sqlReader;
ArrayList dataReadFromDatabase = new ArrayList();
command.Connection = conn;
command.Connection.Open();
command.CommandText = sqlToFetchData;
sqlReader = command.ExecuteReader();
while(sqlReader.Read())
{
object[] values = new object[sqlReader.FieldCount];
sqlReader.GetValues(values);
dataReadFromDatabase.Add(values);
}
command.Connection.Close();
return dataReadFromDatabase;
}
我得到的错误是这个?有趣的是,昨天我想我设法让它如我所愿!
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Object[] may not be used in this context.
at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write8_ArrayOfAnyType(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayListSerializer2.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()