c# - Cannot read data from database into arraylist? -


i have tried solve crazy error when this?

here's first method --> holds 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 egenskapensmallid, emall.mall_namn t_egenskaper egen, t_kopplingmallegenskaper kopp, t_egenskapsmall emall kopp.mall_id = 1 , kopp.egenskap_id = egen.egenskaper_id) d"; dbfetch = executereadsqlqueryarray(sqlreadquery); return dbfetch; } 

then have tried set general webmethod fetch data me.

 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; } 

the error this? funny thing yesterday think managed wanted!

system.invalidoperationexception: there error generating xml document. ---> system.invalidoperationexception: type system.object[] may not used in context. @ system.xml.serialization.xmlserializationwriter.writetypedprimitive(string name, string ns, object o, boolean xsitype) @ microsoft.xml.serialization.generatedassembly.xmlserializationwriter1.write1_object(string n, string ns, object o, boolean isnullable, boolean needtype) @ microsoft.xml.serialization.generatedassembly.xmlserializationwriter1.write8_arrayofanytype(object o) @ microsoft.xml.serialization.generatedassembly.arraylistserializer2.serialize(object objecttoserialize, xmlserializationwriter writer) @ system.xml.serialization.xmlserializer.serialize(xmlwriter xmlwriter, object o, xmlserializernamespaces namespaces, string encodingstyle, string id) --- end of inner exception stack trace --- @ system.xml.serialization.xmlserializer.serialize(xmlwriter xmlwriter, object o, xmlserializernamespaces namespaces, string encodingstyle, string id) @ system.xml.serialization.xmlserializer.serialize(textwriter textwriter, object o, xmlserializernamespaces namespaces) @ system.web.services.protocols.xmlreturnwriter.write(httpresponse response, stream outputstream, object returnvalue) @ system.web.services.protocols.httpserverprotocol.writereturns(object[] returnvalues, stream outputstream) @ system.web.services.protocols.webservicehandler.writereturns(object[] returnvalues) @ system.web.services.protocols.webservicehandler.invoke() 

the problem isn't code getting db such, webmethod trying turn string doesn't know datatype is. cast object (which can mean 1 of million types).

if datatype of simple singular data typetry swapping away arraylist , making generic array, example

list<string> 

the problem array list contains list of objects , serialization processor doesn't know them. hard cast them objects serializable format though or switch class (and make implement serializable).

for example

[serializable] public class profilebasics { /// <summary> /// gets or sets me section /// </summary> [xmlelement("aboutme")] public string aboutme {get; set;} /// <summary> /// gets or sets city name zip code /// </summary> [xmlelement("city")] public string city {get; set;} } 

then list<profilebasics> , web service should still work.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -