列表到数据库的每个项目

问题描述:

我有一个清单



i have a list

List<SalesDetail>  SalesList = new List<SalesDetail>();
SalesDetail detail = new SalesDetail();  





其中SalesDetail是一个类。我有一个按钮(添加),我的代码点击事件的添加按钮是SalesList.Add(详情);其中details是SalesDetail类的对象,其中包含{set;并获得;}



但是当我尝试检索列表中的每个项目时,我只得到最后一项。检索每个项目的代码是





where "SalesDetail" is a class. i have a button (add) and my code on click event of add button is SalesList.Add(details); where details is object of class SalesDetail which contains public variables with {set; and get;}

but when i try to retrieve each item of the list then i only get the last item. my code retrieving each item is

foreach(SalesDetail sd in SalesList)
{

    messageBox.show(sd);

}




我班上的
SalesDetail我有以下代码



in my class SalesDetail i have following code

Public string Brand{get; set;}
Public string Product{get; set;}





i希望从列表中检索每个项目并将其保存到数据库我想知道我在检索时出错了数据..

请帮助

问候bunzitop



i want to retrieve each item from list and save it to database i would like to know where i have made mistake while retrieving the data..
please help
Regards bunzitop

尝试以下代码: -



List< salesdetail> SalesList = new List< salesdetail>();



SalesDetail detail = new SalesDetail();

detail.Brand =123;

detail.Product =12345;



SalesList.Add(detail);



SalesDetail detail1 = new SalesDetail();

detail.Brand =233;

detail.Product =56345;



SalesList.Add(detail1);



现在获取数据:_--



foreach(SalesList中的SalesDetail sd)

{



messageBox.show(sd.Brand + sd。产品);



}



它将逐一显示两条记录。
Try Below code:-

List<salesdetail> SalesList = new List<salesdetail>();

SalesDetail detail = new SalesDetail();
detail.Brand = "123";
detail.Product = "12345";

SalesList.Add(detail);

SalesDetail detail1 = new SalesDetail();
detail.Brand = "233";
detail.Product = "56345";

SalesList.Add(detail1);

Now to Fetch Data :_--

foreach(SalesDetail sd in SalesList)
{

messageBox.show(sd.Brand + sd.Product );

}

It will show two records one by one.