コード例 #1
0
        public WheelModel Read(int id)
        {
            WheelModel model = null;

            String sql = "select brand, Name, Size, Color from [Wheel] where Id=@Id";


            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@Id", id);
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        model       = new WheelModel();
                        model.Id    = id;
                        model.Name  = reader["Name"].ToString();
                        model.Brand = reader["brand"].ToString();
                        model.Size  = reader["Size"].ToString();
                        model.Color = reader["Color"].ToString();
                    }
                }

            return(model);
        }
コード例 #2
0
        public List <WheelModel> List()
        {
            List <WheelModel> WheelList = new List <WheelModel>();

            String sql = "select Id, Brand, Name, size, Color from [Wheel]";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        WheelModel model = new WheelModel();
                        model.Id    = Convert.ToInt32(reader["Id"]);
                        model.Name  = reader["Name"].ToString();
                        model.Brand = reader["brand"].ToString();
                        model.Size  = reader["Size"].ToString();
                        model.Color = reader["Color"].ToString();

                        WheelList.Add(model);
                    }

                    return(WheelList);
                }
        }
コード例 #3
0
        public void Update(WheelModel model)
        {
            String sql = "Update [Wheel] set Brand=@Brand, Name=@Name, Size=@Size, Color=@Color where Id=@Id";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Connection.Open();
                    command.Parameters.AddWithValue("@Brand", model.Brand);
                    command.Parameters.AddWithValue("@Name", model.Name);
                    command.Parameters.AddWithValue("@Size", model.Size);
                    command.Parameters.AddWithValue("@Color", model.Color);
                    command.Parameters.AddWithValue("@Id", model.Id);
                    command.ExecuteNonQuery();
                }
        }
コード例 #4
0
        public bool Create(WheelModel model)
        {
            String sql = "insert into [Wheel] (brand, Name, Size, Color) values (@Brand, @Name, @Size, @Color)";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@Brand", model.Brand);
                    command.Parameters.AddWithValue("@Name", model.Name);
                    command.Parameters.AddWithValue("@Size", model.Size);
                    command.Parameters.AddWithValue("@Color", model.Color);
                    command.Connection.Open();
                    command.ExecuteNonQuery();
                    return(true);
                }
        }