i have an list like this now i need to insert data from the list to DB (sql server 2005).
how can i iterate through list 1 by 1 record and insert them to DB
public class Users
{
public string Name { get; set; }
public int Age { get; set; }
public string Gender { get; set; }
public string Country { get; set; }
}
public MainPage()
{
InitializeComponent();
List myList = new List
{
new Users{ Name="Hiro Nakamura", Gender="M", Age=24, Country="Japan"},
new Users{ Name="Mohinder Suresh",Gender="M", Age=26, Country="India"},
new Users{ Name="Claire Bennette", Gender="F",Age=19, Country="USA"},
new Users{ Name="Matt Parkman", Gender="M",Age=30, Country="USA"},
new Users{ Name="Nathan Patrelli", Gender="M",Age=30, Country="USA"},
new Users{ Name="Peter Patrelli", Gender="M",Age=26, Country="USA"},
new Users{ Name="Mica", Age=12, Gender="M",Country="USA"},
new Users{ Name="Linderman", Gender="M",Age=56, Country="USA"},
new Users{ Name="Ando", Age=24, Gender="M",Country="Japan"},
new Users{ Name="Maya", Age=24, Gender="M",Country="Mexico"},
new Users{ Name="Niki Sanders", Gender="F",Age=26, Country="USA"},
new Users{ Name="Angela Patrelli", Gender="F",Age=26, Country="USA"},
};
MyDataGrid.I开发者_如何学JAVAtemsSource = myList;
}
any help would be greatly appreciated
thanks
You can run a loop on the list 1 item at a time and for each item retrieve all the information from that one entry and parse it into a sql statement and run it against the DB.
Something like:
for i = 0 to listsize-1
{
get ith item;
parse item into a sql insert statement;
run the sql statement on the database;
}
精彩评论