public static void AddWithValue(this DbParameterCollection collection, string parameterName, object parameterValue) { DbParameter parameter = DbFactory.GetCommand().CreateParameter(); parameter.ParameterName = parameterName; parameter.Value = parameterValue; collection.Add(parameter); }
public DbCommand GenerateInsertCommand(T item) { DbCommand command = DbFactory.GetCommand(); StringBuilder sBuilder = new StringBuilder(); sBuilder.AppendFormat("INSERT INTO {0} {1} VALUES {2}", GetTableName(), GetInsertFields(false), GetInsertFields(true)); foreach (var property in typeof(T).GetProperties()) { if (property.Name != "ID") { command.Parameters.AddWithValue("@" + property.Name, property.GetValue(item)); } } command.CommandText = sBuilder.ToString(); return(command); }