コード例 #1
0
        }                                              //비고

        public List <cssDangerousDetail> DataTableToClass(DataTable dt)
        {
            List <cssDangerousDetail> lstData = new List <cssDangerousDetail>();

            if (dt == null)
            {
                return(lstData);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cssDangerousDetail vio   = new cssDangerousDetail();
                PropertyInfo[]     props = vio.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

                foreach (var property in props)
                {
                    string colName = string.Empty;
                    if (dicDangerousDetail.TryGetValue(property.Name, out colName))
                    {
                        property.SetValue(vio, dt.Rows[i][colName].ToString());
                    }
                }

                lstData.Add(vio);
            }


            return(lstData);
        }
コード例 #2
0
        /// <summary>
        /// 위험물 반입신고 저장.
        /// </summary>
        /// <param name="csvFileData"></param>
        private void CopyToDataBaseFromDangerousDetail(DataTable csvFileData)
        {
            cssDangerousDetail        vio     = new cssDangerousDetail();
            List <cssDangerousDetail> lstData = vio.DataTableToClass(csvFileData);

            var bulk = new BulkOperations();

            // var VesselInfo = new List<VesselInfo>();

            using (TransactionScope trans = new TransactionScope())
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    bulk.Setup <cssDangerousDetail>()
                    .ForCollection(lstData)
                    .WithTable("DangerousDetail")
                    .AddAllColumns()
                    .BulkInsertOrUpdate()
                    .MatchTargetOn(x => x.prtAgCd)
                    .MatchTargetOn(x => x.clsgn)
                    .MatchTargetOn(x => x.tkinSe)
                    .MatchTargetOn(x => x.etryptYear)
                    .MatchTargetOn(x => x.etryptCo)

                    .Commit(conn);
                }

                trans.Complete();
            }
        }