Пример #1
0
        /// <summary>
        /// Imports the spreadsheet.  Will throw ArgumentException if
        /// all required properties have not been set.
        /// </summary>
        public void Import()
        {
            CheckProperties();
            List <SqlParameter> sqlParameters = new List <SqlParameter>();
            string sql = string.Format("INSERT INTO {0} SELECT ", TableName);

            //SELECT 1 as loadId,
            for (int i = 0; i < StaticValues.Length; i++)
            {
                sql += string.Format("@{0} as {0}, ", StaticValues[i].AsName);
                sqlParameters.Add(new SqlParameter("@" + StaticValues[i].AsName, StaticValues[i].Value));
            }

            //[Internet E-mail] as smtpAddress,
            //[Lotus Notes mail id] as lotusNotesAddress,
            //[full name] as fullName,
            //[title] as title,
            //[First Name] as firstName,
            //[Last Name] as lastName,
            //[Business Phone] as businessPhone,
            //[Resource Type] as resourceType,
            //[manager] as manager,
            //[business description] as businessDesc,
            //[Cost Center Code] as costCenterCode,
            //[cost center description] as costCenterDescription,
            //[company designation] as companyDesignation,
            //[Department] as department,
            //[Building Code] as buildingCode,
            //[Building Name] as buildingName,
            //[Mail Drop] as mailDrop,
            //[Facility Street Address] as facilityStreetAddress,
            //[City] as city,
            //[State] as state,
            //[Country] as country,
            //[Postal Code] as postalCode
            int it = 0;

            foreach (ExcelToDbPair pair in ExcelToDbColumnMap.ColumnPairs)
            {
                sql += string.Format("[{0}] as [{1}]", pair.ExcelColumn, pair.DbColumn);
                if (it != ExcelToDbColumnMap.ColumnPairs.Length - 1)
                {
                    sql += ", ";
                }
                it++;
            }

            //FROM AmexExcel...People$
            sql += string.Format(" FROM {0}...{1}", ExcelLinkedServerName, SheetName);

            DatabaseUtility.ExecuteSql(sql, sqlParameters.ToArray());
        }