コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }