使用for循环从List <observablecollection>中检索数据以插入数据库中的每个元素

时间:2016-08-03 06:44:04

标签: c# mysql observablecollection

我第一次玩ObservableCollection。我在Web Api Project中的 uploadEventCalendar HttpPost方法中从ObservableCollection列表的对象获取数据。现在我需要检索所有元素并使用单个查询将其放入MySql数据库。我跟随着我做好了准备。

public class ModelEventCalendar
    {
        public string Occasion { get; set; }
        public string OccasionDate { get; set; }
        public string OccasionWeekDay { get; set; }
    }
[HttpPost]
        public string uploadEventCalendar(List<ModelEventCalendar> events)
        {
            query = "truncate table holiday_calendar;";//Removed old entries
            MySqlCommand command = new MySqlCommand(query, conn);
            MySqlDataReader reader;
            conn.Open();
            reader = command.ExecuteReader();
            conn.Close();

            for(int i = 0; i < events.Count; i++)
            {
                  // Here I wan't to get all elements of collection and insert it in holiday_calendar table. How to do?
            }

            return string.Format("Calendar Upload is Successful!");
        }

0 个答案:

没有答案