如题~~~我想传入web service 一个arraylist, 但是老是提示说arraylist 不能转换成object []web services
public DataSet Shopingcart(ArrayList Booklist)
{
string cn = "Data Source=.;Initial Catalog=951;User ID=sa;Password=0591245";
SqlConnection conn = new SqlConnection(cn);
conn.Open();
DataSet ds = new DataSet();
foreach (string s in Booklist)
{
string sql = string.Format("select BookNo,BookName,Prices from BookInfo WHERE BookNo='{0}'", Booklist[0]);
SqlCommand cmd = new SqlCommand(sql, conn); //ds.Tables.Add(newDT);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(ds);
}
return ds;
}网站上 protected void Page_Load(object sender, EventArgs e)
{
object[] Bl = (ArrayList )Session["Booklist"];
BookSearch.Service Shopcart = new BookSearch.Service();
ds = Shopcart.Shopingcart(Bl);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
public DataSet Shopingcart(ArrayList Booklist)
{
string cn = "Data Source=.;Initial Catalog=951;User ID=sa;Password=0591245";
SqlConnection conn = new SqlConnection(cn);
conn.Open();
DataSet ds = new DataSet();
foreach (string s in Booklist)
{
string sql = string.Format("select BookNo,BookName,Prices from BookInfo WHERE BookNo='{0}'", Booklist[0]);
SqlCommand cmd = new SqlCommand(sql, conn); //ds.Tables.Add(newDT);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(ds);
}
return ds;
}网站上 protected void Page_Load(object sender, EventArgs e)
{
object[] Bl = (ArrayList )Session["Booklist"];
BookSearch.Service Shopcart = new BookSearch.Service();
ds = Shopcart.Shopingcart(Bl);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
这样也行?直接用Array B1=(ArrayList )Session["Booklist"];
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections;namespace ConsoleApplication1
{
class Program
{
public Program()
{
ArrayList al = new ArrayList();
al.Add(1);
al.Add(2);
//此时al中有两个元素 //直接调用ToArray()函数进行转换,使用save接收
object[] save = al.ToArray();
} static void Main()
{
Program p1 = new Program(); Console.ReadLine();
}
}}
Ojbect[] 是一个数组
{
ArrayList Bl = (ArrayList)Session["Booklist"];
BookSearch.Service Shopcart = new BookSearch.Service();
ds = Shopcart.Shopingcart(Bl);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
object[] Bl = ((ArrayList)Session["Booklist"]).ToArray();
这个直接用的话,系统报错的,要不然我也不会去想着转了