一个关于arraylist的问题

jiaweihan_001 2011-01-11 05:30:59
我写了一个返回arraylist的方法,

public ArrayList GetEDMHotelInformation(String sName)
{
//填充数据///
}

然后填充数据,返回arraylist,
然后在另一个地方调用这个方法,但是提示:Cannot convert type 'object[]' to 'System.Collections.ArrayList'

我不明白了,我方法返回的是arraylist,怎么在另一个页面实例化的时候就出错,

这个怎么解决,?谢谢。。
...全文
109 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujiazhi 2011-01-12
  • 打赏
  • 举报
回复
做为webservice的返回值,必须要求其是可序列化的
[Serializable]
手抓宝 2011-01-12
  • 打赏
  • 举报
回复
ArrayList 换成 List<string>
jiaweihan_001 2011-01-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wuyq11 的回复:]
ArrayList也不能做为webserver的返回值,因为它不支持序列化。
可以返回1个dataset然后在webApplication在转为ArrayList
[/Quote]

能不能说的具体点啊,我不太懂啊,
或者有更好的方法。
wuyq11 2011-01-11
  • 打赏
  • 举报
回复
ArrayList也不能做为webserver的返回值,因为它不支持序列化。
可以返回1个dataset然后在webApplication在转为ArrayList

jiaweihan_001 2011-01-11
  • 打赏
  • 举报
回复
还有 entity 没有用过,怎么用啊,是不是要导入什么命名啊?
jiaweihan_001 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 nocturnellj 的回复:]
C# code

if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow _row in ds.Tables[0].Rows)
{
//数据表对应的模型实体类
Entity en = new Entity();
en.PropertyId = row["htl_propertyid"].ToString();
en.Eat = ro……
[/Quote]

我在另一个页面,怎么取数据呢?
NocturneLLJ 2011-01-11
  • 打赏
  • 举报
回复

if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow _row in ds.Tables[0].Rows)
{
//数据表对应的模型实体类
Entity en = new Entity();
en.PropertyId = row["htl_propertyid"].ToString();
en.Eat = row["htl_eat2eat"].ToString();
......

//列表收录该实体,进入下一条数据循环
arrHotellist.Add(en);
}
}
NocturneLLJ 2011-01-11
  • 打赏
  • 举报
回复
你的ArrayList的每一项应该是一行数据的实体对象
而不是每把数据库每一个值装进这个列表
jiaweihan_001 2011-01-11
  • 打赏
  • 举报
回复
怎么没有人回啊,该不会斗下班了吧,
jiaweihan_001 2011-01-11
  • 打赏
  • 举报
回复
不好意思,还有一点问题,

我把完整的方法贴出来,


public ArrayList GetEDMHotelInformation(String sName)
{
ArrayList arrHotellist = new ArrayList();
mysqldatabase mysql = new mysqldatabase();
DataSet ds;
if (!String.IsNullOrEmpty(sName))
{
ds = mysql.Select("select * from cm_hotel where htl_name ='" + sName + "' AND sys_deleted<>'Y' ", null);
if (ds.Tables[0].Rows.Count > 0)
{
arrHotellist.Add(ds.Tables[0].Rows[0]["htl_propertyid"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[1]["htl_eat2eat"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[2]["htl_allowreservation"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[3]["htl_brand"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[4]["htl_address"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[5]["htl_country"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[6]["htl_city"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[7]["htl_postcode"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[8]["htl_phone"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[9]["htl_fax"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[10]["htl_email"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[11]["htl_website"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[12]["htl_brief"].ToString());
arrHotellist.Add(ds.Tables[0].Rows[13]["htl_overview"].ToString());
}
}
return arrHotellist;
}

其实我这是做webservice,然后在另一个网站调用,
我想把arrHotellist中的数据取出来,然后分别赋给,比如说"
label1的值是arrHotellist.Add(ds.Tables[0].Rows[3]["htl_brand"].ToString())取的值,
label2的值是arrHotellist.Add(ds.Tables[0].Rows[3]["htl_address"].ToString())取的值,

以此类推,我调用页面不知道该如何赋值了,

EdmWebReference.Service1 edmservice = new EdmWebReference.Service1();



大家帮帮忙,给点方法,谢谢了,

62,040

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧