private void CreateBestInsertCommand(int maxRows) { int numRows = 0; List <string> paramRows = new List <string>(); List <string> insertStantement = new List <string>(); int parmLength = 0; int insertLength = 0; int parmNum = 0; for (int r = 0; r < maxRows; r++) { List <string> inputParms = new List <string>(); List <string> insertValues = new List <string>(); for (int c = 0; c < ParameterSet.Count; c++) { string parName = $"P{parmNum++}"; inputParms.Add($"{parName} {ParameterSet[c].CastValue}"); insertValues.Add($":{parName}"); } string paramNames = string.Join("\n,", inputParms); string insertRow = $"insert into {DestinationTableName} values({ string.Join(",", insertValues.Select(x => x))});"; if (parmLength + insertLength + insertRow.Length + paramNames.Length > MaxCommandLength) { break; } paramRows.Add(paramNames); parmLength += paramNames.Length; insertStantement.Add(insertRow); insertLength += insertRow.Length; foreach (InputParameter parameter in ParameterSet) { FbParameter rowParam = InsertCommand.CreateParameter(); rowParam.DbType = parameter.DbType; //rowParam.IsNullable = parameter.IsNullable; InsertCommand.Parameters.Add(rowParam); } numRows++; } CurrentInsertCount = numRows; InsertCommand.CommandText = (new StringBuilder("execute block (") .Append(string.Join(",\n", paramRows)) .Append(")\nas begin\n") .Append(string.Join("\n", insertStantement)) .Append("\nend") .ToString()); InsertCommand.Prepare(); }