在描述中,我翻译了代码以更好地理解问题
如何在IBindingList中转换数组?因为我的DataGridView
代码:
public class ProductDALC
{
public List<Product> ListProducts() //Product is the table name of my Database named DotNetStore
{
DotNetDataContext DataModel = new DotNetDataContext();
var query = from objProduct in DataModel.Product.AsEnumerable()
select new Product { idProduct = objProducto.CodProduct, Name = objProduct.Name };
return query.ToList();
}
public Array ArrayProducts()
{
DotNetDataContext DataModel = new DotNetDataContext();
var query = from objProduct in DataModel.Product.AsEnumerable()
select new
{
idProduct = ("0000" + Convert.ToString(objProduct.idProduct)).Substring(("0000" + Convert.ToString(objProduct.idProduct)).Length - 4, 4),
Nombre = objProduct.Name,
Cantidad = objProduct.Quantity
};
return query.ToArray();
}
}
答案 0 :(得分:0)
你试试这个:http://msdn.microsoft.com/en-us/library/ms132681.aspx
public BindingList<Product> ArrayProducts()
{
DotNetDataContext DataModel = new DotNetDataContext();
var query = from objProduct in DataModel.Product.AsEnumerable()
select new Product
{
idProduct = ("0000" + Convert.ToString(objProduct.idProduct)).Substring(("0000" + Convert.ToString(objProduct.idProduct)).Length - 4, 4),
Nombre = objProduct.Name,
Cantidad = objProduct.Quantity
};
return new BindingList<Customer>(query.ToList());
}