コード例 #1
0
        public int Update(Karyawan kary)
        {
            int i;

            using (SqlConnection con = new SqlConnection(cs))
            {
                con.Open();
                SqlCommand com = new SqlCommand("InsertUpdateKaryawan", con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@Id", kary.kode);
                com.Parameters.AddWithValue("@nama", kary.nama);
                com.Parameters.AddWithValue("@kd_type", kary.kd_type);
                com.Parameters.AddWithValue("@alamat", kary.alamat);
                com.Parameters.AddWithValue("@Action", "Update");
                i = com.ExecuteNonQuery();
            }
            return(i);
        }
コード例 #2
0
        public int Add(Karyawan kary)
        {
            using (SqlConnection con = new SqlConnection(cs))
            {
                con.Open();
                SqlCommand com = new SqlCommand("InsertUpdateKaryawan", con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@Id", kary.kode);
                com.Parameters.AddWithValue("@nama", kary.nama);
                com.Parameters.AddWithValue("@kd_type", kary.kd_type);
                com.Parameters.AddWithValue("@alamat", kary.alamat);
                com.Parameters.AddWithValue("@Action", "Insert");

                SqlDataReader i = com.ExecuteReader(CommandBehavior.CloseConnection);
                if (i.HasRows)
                {
                    return(0);  // data exist
                }
                else
                {
                    return(1); //data not exist
                }
            }
        }