public static bool GetParameterFormats([NotNull] this DbProviderFactory thisValue, [NotNull] out string nameFormat, [NotNull] out string placeholderFormat) { nameFormat = FMT_PARAMETER_PLACEHOLDER_DEFAULT; placeholderFormat = FMT_PARAMETER_PLACEHOLDER_DEFAULT; DbCommandBuilder builder = thisValue.CreateCommandBuilder(); if (builder == null) { return(false); } builder.RefreshSchema(); string value = (string)GetParameterNameMethod.Invoke(builder, new object[] { "t" }); if (string.IsNullOrEmpty(value)) { return(false); } nameFormat = value.Length == 1 ? "{0}" : value.Left(value.Length - 1) + "{0}"; value = (string)GetParameterPlaceholderMethod.Invoke(builder, new object[] { 0 }); if (string.IsNullOrEmpty(value)) { nameFormat = FMT_PARAMETER_PLACEHOLDER_DEFAULT; return(false); } placeholderFormat = value.Length < 3 ? "{0}" : value.Left(value.Length - 2) + "{0}"; return(true); }
public static DbCommandBuilder CreateCommandBuilder([NotNull] this DbProviderFactory thisValue, IDbDataAdapter adapter = null, ConflictOption conflictOption = ConflictOption.OverwriteChanges, bool setAllValues = true) { DbCommandBuilder builder = thisValue.CreateCommandBuilder(); if (builder == null) { return(null); } builder.DataAdapter = (DbDataAdapter)adapter; builder.RefreshSchema(); builder.ConflictOption = conflictOption; builder.SetAllValues = setAllValues; return(builder); }