i have three different Listview which is Item,quantity and price. All the items for the listview will be added from a textbox. I would like to know how can i store the listview items into my SQl database. Here is the code i use to add item into the listview.
private void SalesAddItemBtn_Click(object sender, RoutedEventArgs e)
{
ListProductName.Items.Add(ComSalesProduct.Text);
ListProductQuantity.Items.Add(txtSalesQuantity.Text);
ListProductCost.Items.Add("RM " + txtSalesCost.Text+".00");
}
Thanks in advance..
Assuming your entity is defined something like this:
public class Order
{
public string product;
public string quantity;
public string cost;
}
You can Zip to combine the lists and update the database:
var orders = ListProductName.Zip(ListProductQuantity, (p, q) => new { Product = p, Quantity = q }).Zip(
ListProductCost, (p, c) => new Order() { product = p.Product, quantity = p.Quantity, cost = c });
db.Orders.InsertAllOnSubmit(orders);
db.SubmitChanges();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.