Beispiel #1
0
        private void BulkInsert(object data, string toTable)
        {
            if (data == null)
            {
                return;
            }

            var sql        = $"INSERT INTO {toTable}(#col#)VALUES";
            var parameters = new DBOParameterCollection();

            if (data is IEnumerable <FrameDLRObject> )
            {
                var cols   = "";
                var values = new StringBuilder();
                var param  = "";
                var list   = (IEnumerable <FrameDLRObject>)data;
                if (list.Count() <= 0)
                {
                    return;
                }
                if (list.ElementAt(0).Keys.Count <= 0)
                {
                    return;
                }


                foreach (var k in list.ElementAt(0).Keys)
                {
                    cols  += $",{k}";
                    param += $",{ParameterFlagChar}{k}#no#";
                }
                sql = sql.Replace("#col#", cols.Substring(1));

                var index = 0;

                foreach (var item in (IEnumerable <FrameDLRObject>)data)
                {
                    values.AppendLine($",({param.Substring(1).Replace("#no#", index + "")})");
                    foreach (var key in item.Keys)
                    {
                        parameters.Add($"{key}{index}", item.GetValue(key));
                    }
                    index++;
                }

                sql += values.ToString().Substring(1);
            }
            ExecuteNoQuery(sql, parameters);
        }
Beispiel #2
0
        private void FillParametersToCommand(DbCommand command, DBOParameterCollection parameters, string sql)
        {
            DBOParameterCollection filtercollection = new DBOParameterCollection();
            string regstr = @"(?<=:)[A-Za-z0-9_]+\d*";
            Regex  reg    = new Regex(regstr);

            foreach (Match m in reg.Matches(sql))
            {
                if (parameters.ContainsKey(m.Value))
                {
                    filtercollection.Add(m.Value, parameters[m.Value]);
                }
            }

            FillParametersToCommand(command, filtercollection);
        }