Exemplo n.º 1
0
            public static int Edit(Moperson T)
            {
                try
                {
                    int r = -1;
                    using (SqlConnection cnn = new SqlConnection(Models.DataBase.Config.GetConnectionString()))
                    {
                        cnn.Open();
                        string     query = "UPDATE Moperson SET address=@address,age=@age,date_of_birth=@date_of_birth,first_name=@first_name,last_name=@last_name WHERE Id=@Id";
                        SqlCommand cmd   = new SqlCommand(query, cnn);

                        cmd.Parameters.AddWithValue("Id", T.Id);
                        cmd.Parameters.AddWithValue("address", T.address);
                        cmd.Parameters.AddWithValue("age", T.age == null ? (object)DBNull.Value  : T.age);
                        cmd.Parameters.AddWithValue("date_of_birth", T.date_of_birth == null ? (object)DBNull.Value  : T.date_of_birth);
                        cmd.Parameters.AddWithValue("first_name", T.first_name);
                        cmd.Parameters.AddWithValue("last_name", T.last_name);

                        r = cmd.ExecuteNonQuery();
                    }

                    return(r);
                }
                catch (Exception Ex)
                {
                    throw Ex;
                }
            }
Exemplo n.º 2
0
            public static int Add(Moperson T)
            {
                try
                {
                    int InsertedID = -1;
                    using (SqlConnection cnn = new SqlConnection(Models.DataBase.Config.GetConnectionString()))
                    {
                        cnn.Open();
                        string query = "INSERT INTO Moperson(address,age,date_of_birth,first_name,last_name)  VALUES (@address,@age,@date_of_birth,@first_name,@last_name)";

                        SqlCommand cmd = new SqlCommand(query, cnn);
                        cmd.Parameters.AddWithValue("address", T.address);
                        cmd.Parameters.AddWithValue("age", T.age == null ? (object)DBNull.Value  : T.age);
                        cmd.Parameters.AddWithValue("date_of_birth", T.date_of_birth == null ? (object)DBNull.Value  : T.date_of_birth);
                        cmd.Parameters.AddWithValue("first_name", T.first_name);
                        cmd.Parameters.AddWithValue("last_name", T.last_name);

                        InsertedID = cmd.ExecuteNonQuery();
                    }

                    return(InsertedID);
                }
                catch (Exception Ex)
                {
                    throw Ex;
                }
            }