Beispiel #1
0
        public void EditUserFromList(int id, string username, string email, string description, string city, string street, User.Category categoryId)
        {
            string edit = "Update Users " +
                          "Set Username=@username, Email=@email, Description = @description, City=@city, Street=@street, CategoryId=@categoryId " +
                          "Where Id=@id";
            SqlCommand command = new SqlCommand(edit, sqlConnection);

            sqlConnection.Open();
            command.Parameters.AddRange(
                new SqlParameter[]
            {
                new SqlParameter {
                    ParameterName = "id", Value = id
                },
                new SqlParameter {
                    ParameterName = "username", Value = username
                },
                new SqlParameter {
                    ParameterName = "email", Value = email
                },
                new SqlParameter {
                    ParameterName = "description", Value = description
                },
                new SqlParameter {
                    ParameterName = "city", Value = city
                },
                new SqlParameter {
                    ParameterName = "street", Value = street
                },
                new SqlParameter {
                    ParameterName = "categoryId", Value = categoryId
                },
            });
            command.ExecuteNonQuery();
            sqlConnection.Close();
        }
Beispiel #2
0
        public void AddUser(string username, string email, string description, string city, string street, User.Category categoryId)
        {
            string addUser = @"Insert into USERS (Username, Email, Description, City, Street) values " +
                             "(@username, @email, @description, @city, @street, @categoryId); select cast(scope_identity() as int);";
            SqlCommand command = new SqlCommand(addUser, sqlConnection);

            sqlConnection.Open();
            command.Parameters.AddRange(new SqlParameter[]
            {
                new SqlParameter {
                    ParameterName = "username", Value = username
                },
                new SqlParameter {
                    ParameterName = "email", Value = email
                },
                new SqlParameter {
                    ParameterName = "description", Value = description
                },
                new SqlParameter {
                    ParameterName = "city", Value = city
                },
                new SqlParameter {
                    ParameterName = "street", Value = street
                },
                new SqlParameter {
                    ParameterName = "categoryId", Value = categoryId
                },
            });
            command.ExecuteNonQuery();
            sqlConnection.Close();
        }