我试图将数据集中的数据添加到List中.这是我在C#中的功能 public ListProductsDAL GetAllProducts(string sqlQuery) { DataSet dsinsert = GetDataSet(sqlQuery, "tblProducts"); ListProductsDAL bPList = new ListProductsDAL();Pro
public List<ProductsDAL> GetAllProducts(string sqlQuery)
{
DataSet dsinsert = GetDataSet(sqlQuery, "tblProducts");
List<ProductsDAL> bPList = new List<ProductsDAL>();
ProductsDALforeach (DataRow item in dsinsert.Tables[0].Rows)
{
this.Product_ID = item["Product_ID"].ToString();
this.ProductDescr= item["ProductDescr"].ToString();
bPList.Add(this);
}
return bPList;
}
数据集中的结果如下
column1 - colum2 A 1 B 2 C 3 D 4
但我认为列表中的结果是:
column1 - colum2 D 1 D 1 D 1 D 1
当我将这组数据插入另一个数据库时,我只得到这个:
column1 - colum2 D 1
我的功能在做什么?
您需要在foreach语句中创建一个新的ProductsDAL.你刚刚更新了同一个.